Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added attribute for to job if not argument present #287

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion rq_scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)})
Expand All @@ -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()

Expand Down Expand Up @@ -420,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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down