From f059f82c70cd81ca715f1825aa084a2427eb435d Mon Sep 17 00:00:00 2001 From: Luis Orozco <34034179+elbergasorozco@users.noreply.github.com> Date: Tue, 21 Mar 2023 16:19:12 -0400 Subject: [PATCH 1/3] Added attribute for to job if not argument present --- rq_scheduler/scheduler.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rq_scheduler/scheduler.py b/rq_scheduler/scheduler.py index 8566303..1965c17 100644 --- a/rq_scheduler/scheduler.py +++ b/rq_scheduler/scheduler.py @@ -206,6 +206,8 @@ def enqueue_at(self, scheduled_time, func, *args, **kwargs): on_success=on_success, on_failure=on_failure) if at_front: job.enqueue_at_front = True + else: + job.enqueue_at_front = False self.connection.zadd(self.scheduled_jobs_key, {job.id: to_unix(scheduled_time)}) return job @@ -234,6 +236,8 @@ def enqueue_in(self, time_delta, func, *args, **kwargs): depends_on=depends_on, on_success=on_success, on_failure=on_failure) if at_front: job.enqueue_at_front = True + else: + job.enqueue_at_front = False self.connection.zadd(self.scheduled_jobs_key, {job.id: to_unix(datetime.utcnow() + time_delta)}) return job @@ -263,6 +267,8 @@ def schedule(self, scheduled_time, func, args=None, kwargs=None, raise ValueError("Can't repeat a job without interval argument") if at_front: job.enqueue_at_front = True + else: + job.enqueue_at_front = False job.save() self.connection.zadd(self.scheduled_jobs_key, {job.id: to_unix(scheduled_time)}) @@ -289,6 +295,8 @@ def cron(self, cron_string, func, args=None, kwargs=None, repeat=None, if at_front: job.enqueue_at_front = True + else: + job.enqueue_at_front = False job.save() From 16f3ae3449651b4454ded47c827b2bf699a0264b Mon Sep 17 00:00:00 2001 From: Luis Orozco <34034179+elbergasorozco@users.noreply.github.com> Date: Tue, 21 Mar 2023 16:52:51 -0400 Subject: [PATCH 2/3] Make backwards compatible with older versions of rq (rq<1.11) --- rq_scheduler/scheduler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rq_scheduler/scheduler.py b/rq_scheduler/scheduler.py index 1965c17..a86dd6c 100644 --- a/rq_scheduler/scheduler.py +++ b/rq_scheduler/scheduler.py @@ -428,7 +428,7 @@ def enqueue_job(self, job): job.meta['repeat'] = int(repeat) - 1 queue = self.get_queue_for_job(job) - queue.enqueue_job(job, at_front=bool(job.enqueue_at_front)) + queue.enqueue_job(job, at_front=bool(getattr(job, "enqueue_at_front", False))) self.connection.zrem(self.scheduled_jobs_key, job.id) if interval: From c4f9a7405e7f5ad56e3fbf0257af8753407f2f43 Mon Sep 17 00:00:00 2001 From: Luis Orozco <34034179+elbergasorozco@users.noreply.github.com> Date: Tue, 2 May 2023 15:48:04 -0400 Subject: [PATCH 3/3] Attempt to fix failing test --- tests/test_scheduler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index ada30f4..ab58b94 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -320,10 +320,10 @@ def test_get_jobs(self): self.assertIn(job, self.scheduler.get_jobs(now)) future_time = now + timedelta(hours=1) job = self.scheduler.enqueue_at(future_time, say_hello) - self.assertIn(job, self.scheduler.get_jobs(timedelta(hours=1, seconds=1))) + self.assertIn(job, self.scheduler.get_jobs(until=timedelta(hours=1, seconds=1))) self.assertIn(job, [j[0] for j in self.scheduler.get_jobs(with_times=True)]) self.assertIsInstance(list(self.scheduler.get_jobs(with_times=True))[0][1], datetime) - self.assertNotIn(job, self.scheduler.get_jobs(timedelta(minutes=59, seconds=59))) + self.assertNotIn(job, self.scheduler.get_jobs(until=timedelta(minutes=59, seconds=59))) def test_get_jobs_slice(self): """