diff --git a/docs/docs/index.md b/docs/docs/index.md index 6335357..a33fa78 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -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` diff --git a/rq/registry.py b/rq/registry.py index 74039fd..2b8b992 100644 --- a/rq/registry.py +++ b/rq/registry.py @@ -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) diff --git a/tests/test_registry.py b/tests/test_registry.py index 295d284..41d0c1c 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -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)