From 89fa8ae0b560ccdaeb54d173dfbea6577a4b2163 Mon Sep 17 00:00:00 2001 From: Ethan Wolinsky <58117461+eswolinsky3241@users.noreply.github.com> Date: Tue, 18 Jul 2023 23:46:48 -0400 Subject: [PATCH] Fix bug with stopped callback in enqueue_many (#1954) * Fix bug with stopped callback in enqueue_many * Add test for callbacks enqueued using enqueue_many --- rq/queue.py | 1 + tests/test_callbacks.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/rq/queue.py b/rq/queue.py index ab7d7d4c..17972ccd 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -818,6 +818,7 @@ class Queue: "retry": job_data.retry, "on_success": job_data.on_success, "on_failure": job_data.on_failure, + "on_stopped": job_data.on_stopped, } # Enqueue jobs without dependencies diff --git a/tests/test_callbacks.py b/tests/test_callbacks.py index 8aa9ad44..2dd29bdf 100644 --- a/tests/test_callbacks.py +++ b/tests/test_callbacks.py @@ -104,6 +104,18 @@ class QueueCallbackTestCase(RQTestCase): job = Job.fetch(id=job.id, connection=self.testconn) self.assertEqual(job.stopped_callback, print) + def test_enqueue_many_callback(self): + queue = Queue('example', connection=self.testconn) + + job_data = Queue.prepare_data( + func=say_hello, on_success=print, on_failure=save_exception, on_stopped=save_result_if_not_stopped + ) + + jobs = queue.enqueue_many([job_data]) + assert jobs[0].success_callback == job_data.on_success + assert jobs[0].failure_callback == job_data.on_failure + assert jobs[0].stopped_callback == job_data.on_stopped + class SyncJobCallback(RQTestCase): def test_success_callback(self):