Skip to content

Commit

Permalink
Merge branch 'master' into python_3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemill committed Jul 29, 2017
2 parents eb4ab7d + f730da4 commit bc150e6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 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
2 changes: 1 addition & 1 deletion tests/conftest.py
Expand Up @@ -21,7 +21,7 @@ def connection(redis_db_num):
try:
yield conn
finally:
conn.flushall()
conn.flushdb()


@pytest.yield_fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_queue.py
Expand Up @@ -118,7 +118,7 @@ def test_schedule_job(mock, queue, connection):
queue.schedule_job(job, dt)

zadd.assert_called_with(queue.scheduler_jobs_key, util.to_unix(dt), job.id)
save.assert_called()
assert save.called


def test_enqueue_job(mock, queue, connection):
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 bc150e6

Please sign in to comment.