queue.enqueue() should set job.origin.

main
Selwin Ong 10 years ago
parent 9320496402
commit 3e674fbe6a

@ -88,8 +88,8 @@ class Job(object):
# Job construction
@classmethod
def create(cls, func, args=None, kwargs=None, connection=None,
result_ttl=None, ttl=None, status=None, description=None, depends_on=None, timeout=None,
id=None):
result_ttl=None, ttl=None, status=None, description=None,
depends_on=None, timeout=None, id=None, origin=None):
"""Creates a new Job instance for the given function, arguments, and
keyword arguments.
"""
@ -107,6 +107,9 @@ class Job(object):
if id is not None:
job.set_id(id)
if origin is not None:
job.origin = origin
# Set the core job tuple properties
job._instance = None
if inspect.ismethod(func):

@ -182,10 +182,11 @@ class Queue(object):
"""
timeout = timeout or self._default_timeout
job = self.job_class.create(func, args, kwargs, connection=self.connection,
job = self.job_class.create(
func, args, kwargs, connection=self.connection,
result_ttl=result_ttl, status=JobStatus.QUEUED,
description=description, depends_on=depends_on, timeout=timeout,
id=job_id)
description=description, depends_on=depends_on,
timeout=timeout, id=job_id, origin=self.name)
# If job depends on an unfinished job, register itself on it's
# parent's dependents instead of enqueueing it.

@ -117,6 +117,7 @@ class TestQueue(RQTestCase):
# say_hello spec holds which queue this is sent to
job = q.enqueue(say_hello, 'Nick', foo='bar')
job_id = job.id
self.assertEqual(job.origin, q.name)
# Inspect data inside Redis
q_key = 'rq:queue:default'
@ -131,14 +132,12 @@ class TestQueue(RQTestCase):
job = Job.create(func=say_hello, args=('Nick',), kwargs=dict(foo='bar'))
# Preconditions
self.assertIsNone(job.origin)
self.assertIsNone(job.enqueued_at)
# Action
q.enqueue_job(job)
# Postconditions
self.assertEquals(job.origin, q.name)
self.assertIsNotNone(job.enqueued_at)
def test_pop_job_id(self):

Loading…
Cancel
Save