diff options
author | Bradley Young <young.bradley@gmail.com> | 2014-11-12 09:04:40 -0500 |
---|---|---|
committer | Bradley Young <young.bradley@gmail.com> | 2014-11-12 09:04:40 -0500 |
commit | 5caccaabfe213e98a5a03a6f5914662d8c322134 (patch) | |
tree | 7edb9807dac4d0ceeb6e7230c715140508ba6390 /rq | |
parent | 0dbe68527ce029b5fd0a51d229344322d81f149e (diff) | |
download | rq-5caccaabfe213e98a5a03a6f5914662d8c322134.tar.gz |
Adding optional list handling to the exc_handler option in Worker.
Adding command line --exception_handler option (with multiple entries allowed) to `rq worker`
Added tests for command line options.
Diffstat (limited to 'rq')
-rwxr-xr-x | rq/cli/cli.py | 9 | ||||
-rw-r--r-- | rq/worker.py | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/rq/cli/cli.py b/rq/cli/cli.py index 18979dc..d5fc1a1 100755 --- a/rq/cli/cli.py +++ b/rq/cli/cli.py @@ -132,10 +132,11 @@ def info(url, path, interval, raw, only_queues, only_workers, by_queue, queues): @click.option('--verbose', '-v', is_flag=True, help='Show more output') @click.option('--quiet', '-q', is_flag=True, help='Show less output') @click.option('--sentry-dsn', envvar='SENTRY_DSN', help='Report exceptions to this Sentry DSN') +@click.option('--exception-handler', help='Exception handler(s) to use', multiple=True) @click.option('--pid', help='Write the process ID number to a file at the specified path') @click.argument('queues', nargs=-1) def worker(url, config, burst, name, worker_class, job_class, queue_class, path, results_ttl, worker_ttl, - verbose, quiet, sentry_dsn, pid, queues): + verbose, quiet, sentry_dsn, exception_handler, pid, queues): """Starts an RQ worker.""" if path: @@ -157,6 +158,9 @@ def worker(url, config, burst, name, worker_class, job_class, queue_class, path, cleanup_ghosts(conn) worker_class = import_attribute(worker_class) queue_class = import_attribute(queue_class) + exc_handler = [] + for h in exception_handler: + exc_handler.append(import_attribute(h)) try: queues = [queue_class(queue, connection=conn) for queue in queues] @@ -165,7 +169,8 @@ def worker(url, config, burst, name, worker_class, job_class, queue_class, path, connection=conn, default_worker_ttl=worker_ttl, default_result_ttl=results_ttl, - job_class=job_class) + job_class=job_class, + exc_handler=exc_handler) # Should we configure Sentry? if sentry_dsn: diff --git a/rq/worker.py b/rq/worker.py index bf40a65..55ff452 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -140,7 +140,10 @@ class Worker(object): # By default, push the "move-to-failed-queue" exception handler onto # the stack self.push_exc_handler(self.move_to_failed_queue) - if exc_handler is not None: + if isinstance(exc_handler, list): + for h in exc_handler: + self.push_exc_handler(h) + elif exc_handler is not None: self.push_exc_handler(exc_handler) if job_class is not None: |