From 8bfbeac67d96376fb468a1aa24cb1ae7b88ff3eb Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Fri, 3 Jul 2015 17:04:01 +0700 Subject: [PATCH] Running rqworker without specifiying --exception-handler shouldn't override default behavior. --- rq/cli/cli.py | 2 +- tests/test_cli.py | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/rq/cli/cli.py b/rq/cli/cli.py index 40f528f..da156d3 100755 --- a/rq/cli/cli.py +++ b/rq/cli/cli.py @@ -184,7 +184,7 @@ def worker(url, config, burst, name, worker_class, job_class, queue_class, path, default_worker_ttl=worker_ttl, default_result_ttl=results_ttl, job_class=job_class, - exception_handlers=exception_handlers) + exception_handlers=exception_handlers or None) # Should we configure Sentry? if sentry_dsn: diff --git a/tests/test_cli.py b/tests/test_cli.py index 6744a11..1a812ae 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -80,24 +80,19 @@ class TestRQCli(RQTestCase): q = Queue() failed_q = get_failed_queue() failed_q.empty() - # Preconditions - self.assertEquals(failed_q.count, 0) - self.assertEquals(q.count, 0) - - # Action - job = q.enqueue(div_by_zero) - self.assertEquals(q.count, 1) runner = CliRunner() - result = runner.invoke(main, ['worker', '-u', self.redis_url, '-b', '--exception-handler', 'tests.fixtures.black_hole']) - self.assertEqual(result.exit_code, 0) - # Postconditions - self.assertEquals(q.count, 0) - self.assertEquals(failed_q.count, 0) - - # Check the job - job = Job.fetch(job.id) - self.assertEquals(job.is_failed, True) + + # If exception handler is not given, failed job goes to FailedQueue + q.enqueue(div_by_zero) + runner.invoke(main, ['worker', '-u', self.redis_url, '-b']) + self.assertEquals(failed_q.count, 1) + + # Black hole exception handler doesn't add failed jobs to FailedQueue + q.enqueue(div_by_zero) + runner.invoke(main, ['worker', '-u', self.redis_url, '-b', + '--exception-handler', 'tests.fixtures.black_hole']) + self.assertEquals(failed_q.count, 1) def test_suspend_and_resume(self): """rq suspend -u