archivebox_worker.py 905 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox worker'
  4. import sys
  5. import json
  6. import rich_click as click
  7. @click.command()
  8. @click.argument('worker_type')
  9. @click.option('--wait-for-first-event', is_flag=True)
  10. @click.option('--exit-on-idle', is_flag=True)
  11. def main(worker_type: str, wait_for_first_event: bool, exit_on_idle: bool):
  12. """Start an ArchiveBox worker process of the given type"""
  13. from workers.worker import get_worker_type
  14. # allow piping in events to process from stdin
  15. # if not sys.stdin.isatty():
  16. # for line in sys.stdin.readlines():
  17. # Event.dispatch(event=json.loads(line), parent=None)
  18. # run the actor
  19. Worker = get_worker_type(worker_type)
  20. for event in Worker.run(wait_for_first_event=wait_for_first_event, exit_on_idle=exit_on_idle):
  21. print(event)
  22. if __name__ == '__main__':
  23. main()