summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelwin Ong <selwin.ong@gmail.com>2020-01-21 19:50:13 +0700
committerGitHub <noreply@github.com>2020-01-21 19:50:13 +0700
commitccfd4a02cbc9130c845b64ca6b5b7510c99fadde (patch)
tree95a5d02f42e472cca607375732ac68c04118f96d
parent927fb5a3ed7fe5465afb0ea0f006a91cc72d60e5 (diff)
downloadrq-ccfd4a02cbc9130c845b64ca6b5b7510c99fadde.tar.gz
Failed jobs will now auto expire (#1182)
-rw-r--r--rq/registry.py2
-rw-r--r--tests/test_registry.py33
2 files changed, 17 insertions, 18 deletions
diff --git a/rq/registry.py b/rq/registry.py
index 9232ddf..25c3bae 100644
--- a/rq/registry.py
+++ b/rq/registry.py
@@ -197,7 +197,7 @@ class FailedJobRegistry(BaseRegistry):
job.exc_info = exc_string
job.save(pipeline=p, include_meta=False)
- job.cleanup(ttl=-1, pipeline=p) # failed job won't expire
+ job.cleanup(ttl=ttl, pipeline=p)
p.zadd(self.key, {job.id: score})
if not pipeline:
diff --git a/tests/test_registry.py b/tests/test_registry.py
index b7921d1..8938c24 100644
--- a/tests/test_registry.py
+++ b/tests/test_registry.py
@@ -318,26 +318,25 @@ class TestFailedJobRegistry(RQTestCase):
timestamp = current_timestamp()
registry.add(job)
- self.assertLess(
- self.testconn.zscore(key, job.id),
- timestamp + DEFAULT_FAILURE_TTL + 2
- )
- self.assertGreater(
- self.testconn.zscore(key, job.id),
- timestamp + DEFAULT_FAILURE_TTL - 2
- )
+ score = self.testconn.zscore(key, job.id)
+ self.assertLess(score, timestamp + DEFAULT_FAILURE_TTL + 2)
+ self.assertGreater(score, timestamp + DEFAULT_FAILURE_TTL - 2)
+
+ # Job key will also expire
+ job_ttl = self.testconn.ttl(job.key)
+ self.assertLess(job_ttl, DEFAULT_FAILURE_TTL + 2)
+ self.assertGreater(job_ttl, DEFAULT_FAILURE_TTL - 2)
timestamp = current_timestamp()
ttl = 5
- registry.add(job, ttl=5)
- self.assertLess(
- self.testconn.zscore(key, job.id),
- timestamp + ttl + 2
- )
- self.assertGreater(
- self.testconn.zscore(key, job.id),
- timestamp + ttl - 2
- )
+ registry.add(job, ttl=ttl)
+ score = self.testconn.zscore(key, job.id)
+ self.assertLess(score, timestamp + ttl + 2)
+ self.assertGreater(score, timestamp + ttl - 2)
+
+ job_ttl = self.testconn.ttl(job.key)
+ self.assertLess(job_ttl, ttl + 2)
+ self.assertGreater(job_ttl, ttl - 2)
def test_requeue(self):
"""FailedJobRegistry.requeue works properly"""