Cleanup job hashes for jobs without result, too.

main
Vincent Driessen 13 years ago
parent f07d28db86
commit 7ef3b5ade8

@ -333,14 +333,19 @@ class Worker(object):
fq.quarantine(job, exc_info=traceback.format_exc())
return False
else:
if rv is None:
self.log.info('Job OK')
else:
self.log.info('Job OK, result = %s' % (yellow(unicode(rv)),))
if rv is not None:
p = conn.pipeline()
p.hset(job.key, 'result', dumps(rv))
p.expire(job.key, self.rv_ttl)
p.execute()
else:
# Cleanup immediately
job.delete()
return True

@ -1,6 +1,6 @@
import os
from tests import RQTestCase
from tests.fixtures import say_hello, div_by_zero, create_file
from tests.fixtures import say_hello, div_by_zero, do_nothing, create_file
from tests.helpers import strip_milliseconds
from rq import Queue, Worker, Job
@ -111,3 +111,21 @@ class TestWorker(RQTestCase):
# Should not have created evidence of execution
self.assertEquals(os.path.exists(SENTINEL_FILE), False)
def test_cleaning_up_of_jobs(self):
"""Jobs get cleaned up after successful execution."""
q = Queue()
job_with_rv = q.enqueue(say_hello, 'Franklin')
job_without_rv = q.enqueue(do_nothing)
# Job hashes exists
self.assertEquals(self.testconn.type(job_with_rv.key), 'hash')
self.assertEquals(self.testconn.type(job_without_rv.key), 'hash')
# Execute the job
w = Worker([q])
w.work(burst=True)
# Jobs with results expire after a certain TTL, while jobs without
# results are immediately removed
assert self.testconn.ttl(job_with_rv.key) > 0
assert self.testconn.exists(job_without_rv.key) == False

Loading…
Cancel
Save