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.exc_info = exc_string
job.save(pipeline=p, include_meta=False) 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}) p.zadd(self.key, {job.id: score})
if not pipeline: if not pipeline:

@ -318,26 +318,25 @@ class TestFailedJobRegistry(RQTestCase):
timestamp = current_timestamp() timestamp = current_timestamp()
registry.add(job) registry.add(job)
self.assertLess( score = self.testconn.zscore(key, job.id)
self.testconn.zscore(key, job.id), self.assertLess(score, timestamp + DEFAULT_FAILURE_TTL + 2)
timestamp + DEFAULT_FAILURE_TTL + 2 self.assertGreater(score, timestamp + DEFAULT_FAILURE_TTL - 2)
)
self.assertGreater( # Job key will also expire
self.testconn.zscore(key, job.id), job_ttl = self.testconn.ttl(job.key)
timestamp + DEFAULT_FAILURE_TTL - 2 self.assertLess(job_ttl, DEFAULT_FAILURE_TTL + 2)
) self.assertGreater(job_ttl, DEFAULT_FAILURE_TTL - 2)
timestamp = current_timestamp() timestamp = current_timestamp()
ttl = 5 ttl = 5
registry.add(job, ttl=5) registry.add(job, ttl=ttl)
self.assertLess( score = self.testconn.zscore(key, job.id)
self.testconn.zscore(key, job.id), self.assertLess(score, timestamp + ttl + 2)
timestamp + ttl + 2 self.assertGreater(score, timestamp + ttl - 2)
)
self.assertGreater( job_ttl = self.testconn.ttl(job.key)
self.testconn.zscore(key, job.id), self.assertLess(job_ttl, ttl + 2)
timestamp + ttl - 2 self.assertGreater(job_ttl, ttl - 2)
)
def test_requeue(self): def test_requeue(self):
"""FailedJobRegistry.requeue works properly""" """FailedJobRegistry.requeue works properly"""

Loading…
Cancel
Save