introduce job.update_meta() to store updated meta to Redis (#823)

* introduce job.update_meta() to store updated meta to Redis

This closes nvie/rq#811

* rename update_meta to save_meta
main
Alexey Katichev 8 years ago committed by Selwin Ong
parent fe84828d72
commit a0113c83cf

@ -493,6 +493,11 @@ class Job(object):
connection.hmset(key, self.to_dict(include_meta=include_meta))
self.cleanup(self.ttl, pipeline=connection)
def save_meta(self):
"""Stores job meta from the job instance to the corresponding Redis key."""
meta = dumps(self.meta)
self.connection.hset(self.key, 'meta', meta)
def cancel(self):
"""Cancels the given job, which will prevent the job from ever being
ran (or inspected).

@ -272,6 +272,26 @@ class TestJob(RQTestCase):
job2 = Job.fetch(job.id)
self.assertEqual(job2.meta['foo'], 'bar')
def test_custom_meta_is_rewriten_by_save_meta(self):
"""New meta data can be stored by save_meta."""
job = Job.create(func=fixtures.say_hello, args=('Lionel',))
job.save()
serialized = job.to_dict()
job.meta['foo'] = 'bar'
job.save_meta()
raw_meta = self.testconn.hget(job.key, 'meta')
self.assertEqual(loads(raw_meta)['foo'], 'bar')
job2 = Job.fetch(job.id)
self.assertEqual(job2.meta['foo'], 'bar')
# nothing else was changed
serialized2 = job2.to_dict()
serialized2.pop('meta')
self.assertDictEqual(serialized, serialized2)
def test_result_ttl_is_persisted(self):
"""Ensure that job's result_ttl is set properly"""
job = Job.create(func=fixtures.say_hello, args=('Lionel',), result_ttl=10)

Loading…
Cancel
Save