|
|
@ -20,7 +20,7 @@ from tests import RQTestCase, slow
|
|
|
|
from tests.fixtures import (create_file, create_file_after_timeout,
|
|
|
|
from tests.fixtures import (create_file, create_file_after_timeout,
|
|
|
|
div_by_zero, do_nothing, say_hello, say_pid,
|
|
|
|
div_by_zero, do_nothing, say_hello, say_pid,
|
|
|
|
run_dummy_heroku_worker, access_self,
|
|
|
|
run_dummy_heroku_worker, access_self,
|
|
|
|
modify_self)
|
|
|
|
modify_self, modify_self_and_error)
|
|
|
|
from tests.helpers import strip_microseconds
|
|
|
|
from tests.helpers import strip_microseconds
|
|
|
|
|
|
|
|
|
|
|
|
from rq import (get_failed_queue, Queue, SimpleWorker, Worker,
|
|
|
|
from rq import (get_failed_queue, Queue, SimpleWorker, Worker,
|
|
|
@ -621,7 +621,34 @@ class TestWorker(RQTestCase):
|
|
|
|
w.work(burst=True)
|
|
|
|
w.work(burst=True)
|
|
|
|
|
|
|
|
|
|
|
|
job_check = Job.fetch(job.id)
|
|
|
|
job_check = Job.fetch(job.id)
|
|
|
|
self.assertEqual(set(job_check.meta.keys()), {'foo', 'baz', 'newinfo'})
|
|
|
|
self.assertEqual(set(job_check.meta.keys()),
|
|
|
|
|
|
|
|
set(['foo', 'baz', 'newinfo']))
|
|
|
|
|
|
|
|
self.assertEqual(job_check.meta['foo'], 'bar')
|
|
|
|
|
|
|
|
self.assertEqual(job_check.meta['baz'], 10)
|
|
|
|
|
|
|
|
self.assertEqual(job_check.meta['newinfo'], 'waka')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_self_modification_persistence_with_error(self):
|
|
|
|
|
|
|
|
"""Make sure that any meta modification done by
|
|
|
|
|
|
|
|
the job itself persists completely through the
|
|
|
|
|
|
|
|
queue/worker/job stack -- even if the job errored"""
|
|
|
|
|
|
|
|
q = Queue()
|
|
|
|
|
|
|
|
failed_q = get_failed_queue()
|
|
|
|
|
|
|
|
# Also make sure that previously existing metadata
|
|
|
|
|
|
|
|
# persists properly
|
|
|
|
|
|
|
|
job = q.enqueue(modify_self_and_error, meta={'foo': 'bar', 'baz': 42},
|
|
|
|
|
|
|
|
args=[{'baz': 10, 'newinfo': 'waka'}])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w = Worker([q])
|
|
|
|
|
|
|
|
w.work(burst=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Postconditions
|
|
|
|
|
|
|
|
self.assertEqual(q.count, 0)
|
|
|
|
|
|
|
|
self.assertEqual(failed_q.count, 1)
|
|
|
|
|
|
|
|
self.assertEqual(w.get_current_job_id(), None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
job_check = Job.fetch(job.id)
|
|
|
|
|
|
|
|
self.assertEqual(set(job_check.meta.keys()),
|
|
|
|
|
|
|
|
set(['foo', 'baz', 'newinfo']))
|
|
|
|
self.assertEqual(job_check.meta['foo'], 'bar')
|
|
|
|
self.assertEqual(job_check.meta['foo'], 'bar')
|
|
|
|
self.assertEqual(job_check.meta['baz'], 10)
|
|
|
|
self.assertEqual(job_check.meta['baz'], 10)
|
|
|
|
self.assertEqual(job_check.meta['newinfo'], 'waka')
|
|
|
|
self.assertEqual(job_check.meta['newinfo'], 'waka')
|
|
|
|