From bc5bb1fba2988ed017b6c0cfd563f94bdcb4d451 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 31 Jul 2022 15:53:18 +0700 Subject: [PATCH] Revert "Jobs that are run synchronously should always raise an exception" (#1682) This reverts commit 0d21e714c33cfefba51a8c2b714a735bcad1264d. --- rq/queue.py | 1 - tests/test_callbacks.py | 30 +++--------------------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index f7e6e3f..3472d69 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -594,7 +594,6 @@ class Queue: job.set_status(JobStatus.FAILED) if job.failure_callback: job.failure_callback(job, self.connection, *sys.exc_info()) - raise else: if job.success_callback: job.success_callback(job, self.connection, job.result) diff --git a/tests/test_callbacks.py b/tests/test_callbacks.py index d115a6a..8d8edc7 100644 --- a/tests/test_callbacks.py +++ b/tests/test_callbacks.py @@ -1,5 +1,4 @@ from datetime import timedelta -from uuid import uuid4 from tests import RQTestCase from tests.fixtures import div_by_zero, erroneous_callback, save_exception, save_result, say_hello @@ -60,13 +59,7 @@ class SyncJobCallback(RQTestCase): job.result ) - # Callback is not executed when job fails - job_id = str(uuid4()) - try: - job = queue.enqueue(div_by_zero, on_success=save_result, job_id=job_id) - except TypeError: - pass - job = Job.fetch(id=job_id) + job = queue.enqueue(div_by_zero, on_success=save_result) self.assertEqual(job.get_status(), JobStatus.FAILED) self.assertFalse(self.testconn.exists('success_callback:%s' % job.id)) @@ -74,32 +67,15 @@ class SyncJobCallback(RQTestCase): """queue.enqueue* methods with on_failure is persisted correctly""" queue = Queue(is_async=False) - job_id = str(uuid4()) - try: - job = queue.enqueue(div_by_zero, on_failure=save_exception, job_id=job_id) - except: - pass - job = Job.fetch(id=job_id) + job = queue.enqueue(div_by_zero, on_failure=save_exception) self.assertEqual(job.get_status(), JobStatus.FAILED) self.assertIn('div_by_zero', self.testconn.get('failure_callback:%s' % job.id).decode()) - # If there's no failure callback, exception should be raised - job_id = str(uuid4()) - with self.assertRaises(TypeError): - job = queue.enqueue(div_by_zero, on_success=save_result, job_id=job_id) - job = Job.fetch(id=job_id) + job = queue.enqueue(div_by_zero, on_success=save_result) self.assertEqual(job.get_status(), JobStatus.FAILED) self.assertFalse(self.testconn.exists('failure_callback:%s' % job.id)) - # If failure callback is specified, exception is raised after callback is executed - job_id = str(uuid4()) - with self.assertRaises(TypeError): - job = queue.enqueue(div_by_zero, on_failure=save_exception, job_id=job_id) - job = Job.fetch(id=job_id) - self.assertEqual(job.get_status(), JobStatus.FAILED) - self.assertTrue(self.testconn.exists('failure_callback:%s' % job.id)) - class WorkerCallbackTestCase(RQTestCase): def test_success_callback(self):