utils.py 857 B

1234567891011121314151617181920212223242526272829
  1. import os
  2. from traceback import print_tb
  3. import click
  4. def work_on_rq(redis_queue, exc_handler=None, max_jobs=None):
  5. # we only want this import distinction to matter when we actually are testing
  6. if os.name == "nt":
  7. from rq_win import WindowsWorker as SimpleWorker
  8. else:
  9. from rq import SimpleWorker
  10. exc_handlers = []
  11. if exc_handler is not None:
  12. exc_handlers.append(exc_handler)
  13. print("STARTING SIMPLE RQ WORKER, seeing %d job(s)" % redis_queue.count)
  14. worker = SimpleWorker(
  15. [redis_queue],
  16. connection=redis_queue.connection,
  17. exception_handlers=exc_handlers,
  18. )
  19. worker.work(burst=True, max_jobs=max_jobs)
  20. def exception_reporter(job, exc_type, exc_value, traceback):
  21. print_tb(traceback)
  22. click.echo("HANDLING RQ WORKER EXCEPTION: %s:%s\n" % (exc_type, exc_value))