Issue 872 (#954)

* Fixes #872 - Use -1 to indicate infinite ttl

* Fixes #872 Restored comma

* #872 Code review fix
main
Theofanis Despoudis 7 years ago committed by Selwin Ong
parent 531fde8e3c
commit d6b12c2402

@ -65,7 +65,8 @@ job function.
and marked as `failed`. Its default unit is second and it can be an integer or a string representing an integer(e.g. `2`, `'2'`). Furthermore, it can be a string with specify unit including hour, minute, second(e.g. `'1h'`, `'3m'`, `'5s'`).
* `result_ttl` specifies the expiry time of the key where the job result will
be stored
* `ttl` specifies the maximum queued time of the job before it'll be cancelled
* `ttl` specifies the maximum queued time of the job before it'll be cancelled.
If you specify a value of `-1` you indicate an infinite job ttl and it will run indefinitely
* `depends_on` specifies another job (or job id) that must complete before this
job will be queued
* `job_id` allows you to manually specify this job's `job_id`

@ -39,8 +39,10 @@ class BaseRegistry(object):
return self.connection.zcard(self.key)
def add(self, job, ttl=0, pipeline=None):
"""Adds a job to a registry with expiry time of now + ttl."""
"""Adds a job to a registry with expiry time of now + ttl, unless it's -1 which is set to +inf"""
score = ttl if ttl < 0 else current_timestamp() + ttl
if score == -1:
score = '+inf'
if pipeline is not None:
return pipeline.zadd(self.key, score, job.id)

@ -51,9 +51,9 @@ class TestRegistry(RQTestCase):
self.assertLess(self.testconn.zscore(self.registry.key, job.id),
timestamp + 1002)
# Ensure that a timeout of -1 results in a score of -1
# Ensure that a timeout of -1 results in a score of inf
self.registry.add(job, -1)
self.assertEqual(self.testconn.zscore(self.registry.key, job.id), -1)
self.assertEqual(self.testconn.zscore(self.registry.key, job.id), float('inf'))
# Ensure that job is properly removed from sorted set
self.registry.remove(job)

Loading…
Cancel
Save