Skip to content

Commit

Permalink
Merge pull request #16 from mikemill/jobs_schedule
Browse files Browse the repository at this point in the history
Get a list of all the scheduled jobs with times
  • Loading branch information
mikemill committed Jul 29, 2017
2 parents 4277687 + 3d4faba commit f730da4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rq_retry_scheduler/scheduler.py
Expand Up @@ -132,6 +132,15 @@ def enqueue_jobs(self):
queue.enqueue_job(job)
self.remove_job(job.id)

def schedule(self):
"""Returns the job ids and when they are scheduled to be queued"""
data = self.connection.zrange(
self.scheduler_jobs_key, 0, -1, withscores=True)

return [
(job_id, datetime.utcfromtimestamp(ts))
for job_id, ts in data]

def run(self, burst=False):
self.log.info('Starting RQ Retry Scheduler..')

Expand Down
16 changes: 16 additions & 0 deletions tests/test_scheduler.py
Expand Up @@ -259,3 +259,19 @@ def test_make_repat_job(scheduler):
assert repeat_job.func == job.func
assert repeat_job.args == job.args
assert repeat_job.kwargs == job.kwargs


def test_schedule(scheduler, mock, connection):
assert scheduler.schedule() == []

dt = datetime.utcnow().replace(microsecond=0)
scheduler.current_time = lambda: dt

job_id = b'unittest'

ret = [(job_id, to_unix(dt))]
mock.patch.object(connection, 'zrange', return_value=ret)

expected = [(job_id, dt)]

assert scheduler.schedule() == expected

0 comments on commit f730da4

Please sign in to comment.