Failed jobs will now auto expire (#1182)

main
Selwin Ong 5 years ago committed by GitHub
parent 927fb5a3ed
commit ccfd4a02cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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:

@ -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"""

Loading…
Cancel
Save