From 531fde8e3c09825ae230a55f369d5f54e1c20f90 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Mon, 7 May 2018 18:18:45 +0800 Subject: [PATCH] worker.main_work_horse should always return 0 --- rq/worker.py | 5 ++--- tests/test_worker.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rq/worker.py b/rq/worker.py index aeed67d..41e4063 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -678,7 +678,7 @@ class Worker(object): # os._exit() is the way to exit from childs after a fork(), in # constrast to the regular sys.exit() - os._exit(int(not success)) + os._exit(0) def setup_work_horse_signals(self): """Setup signal handing for the newly spawned work horse.""" @@ -801,8 +801,7 @@ class Worker(object): self.handle_job_success(job=job, queue=queue, started_job_registry=started_job_registry) - except Exception: - + except: job.ended_at = utcnow() self.handle_job_failure(job=job, started_job_registry=started_job_registry) diff --git a/tests/test_worker.py b/tests/test_worker.py index c11c06c..d9c88b6 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -871,7 +871,7 @@ class WorkerShutdownTestCase(TimeoutTestCase, RQTestCase): @slow def test_working_worker_cold_shutdown(self): - """worker with an ongoing job receiving double SIGTERM signal and shutting down immediately""" + """Busy worker shuts down immediately on double SIGTERM signal""" fooq = Queue('foo') w = Worker(fooq) sentinel_file = '/tmp/.rq_sentinel_cold' @@ -1045,13 +1045,6 @@ class HerokuWorkerShutdownTestCase(TimeoutTestCase, RQTestCase): class TestExceptionHandlerMessageEncoding(RQTestCase): - def test_handle_exception_handles_non_ascii_in_exception_message(self): - """Test that handle_exception doesn't crash on non-ascii in exception message.""" - self.worker.handle_exception(Mock(), *self.exc_info) - - def test_move_to_failed_queue_handles_non_ascii_in_exception_message(self): - """Test that move_to_failed_queue doesn't crash on non-ascii in exception message.""" - self.worker.move_to_failed_queue(Mock(), *self.exc_info) def setUp(self): super(TestExceptionHandlerMessageEncoding, self).setUp() @@ -1063,3 +1056,11 @@ class TestExceptionHandlerMessageEncoding(RQTestCase): raise Exception(u"💪") except: self.exc_info = sys.exc_info() + + def test_handle_exception_handles_non_ascii_in_exception_message(self): + """worker.handle_exception doesn't crash on non-ascii in exception message.""" + self.worker.handle_exception(Mock(), *self.exc_info) + + def test_move_to_failed_queue_handles_non_ascii_in_exception_message(self): + """Test that move_to_failed_queue doesn't crash on non-ascii in exception message.""" + self.worker.move_to_failed_queue(Mock(), *self.exc_info)