Rename Job.for_call() -> Job.create().

This fixes #34.
main
Vincent Driessen 13 years ago
parent 7e0b843d06
commit 5717a0ba15

@ -26,7 +26,7 @@ class Job(object):
# Job construction # Job construction
@classmethod @classmethod
def for_call(cls, func, *args, **kwargs): def create(cls, func, *args, **kwargs):
"""Creates a new Job instance for the given function, arguments, and """Creates a new Job instance for the given function, arguments, and
keyword arguments. keyword arguments.
""" """

@ -105,7 +105,7 @@ class Queue(object):
'Functions from the __main__ module cannot be processed ' 'Functions from the __main__ module cannot be processed '
'by workers.') 'by workers.')
job = Job.for_call(f, *args, **kwargs) job = Job.create(f, *args, **kwargs)
return self.enqueue_job(job) return self.enqueue_job(job)
def enqueue_job(self, job, set_meta_data=True): def enqueue_job(self, job, set_meta_data=True):

@ -32,7 +32,7 @@ class TestJob(RQTestCase):
def test_create_typical_job(self): def test_create_typical_job(self):
"""Creation of jobs for function calls.""" """Creation of jobs for function calls."""
job = Job.for_call(arbitrary_function, 3, 4, z=2) job = Job.create(arbitrary_function, 3, 4, z=2)
# Jobs have a random UUID # Jobs have a random UUID
self.assertIsNotNone(job.id) self.assertIsNotNone(job.id)
@ -52,7 +52,7 @@ class TestJob(RQTestCase):
def test_save(self): # noqa def test_save(self): # noqa
"""Storing jobs.""" """Storing jobs."""
job = Job.for_call(arbitrary_function, 3, 4, z=2) job = Job.create(arbitrary_function, 3, 4, z=2)
# Saving creates a Redis hash # Saving creates a Redis hash
self.assertEquals(self.testconn.exists(job.key), False) self.assertEquals(self.testconn.exists(job.key), False)
@ -98,7 +98,7 @@ class TestJob(RQTestCase):
def test_persistence_of_typical_jobs(self): def test_persistence_of_typical_jobs(self):
"""Storing typical jobs.""" """Storing typical jobs."""
job = Job.for_call(arbitrary_function, 3, 4, z=2) job = Job.create(arbitrary_function, 3, 4, z=2)
job.save() job.save()
expected_date = strip_milliseconds(job.created_at) expected_date = strip_milliseconds(job.created_at)
@ -113,7 +113,7 @@ class TestJob(RQTestCase):
['created_at', 'data', 'description']) ['created_at', 'data', 'description'])
def test_store_then_fetch(self): def test_store_then_fetch(self):
job = Job.for_call(arbitrary_function, 3, 4, z=2) job = Job.create(arbitrary_function, 3, 4, z=2)
job.save() job.save()
job2 = Job.fetch(job.id) job2 = Job.fetch(job.id)
@ -132,7 +132,7 @@ class TestJob(RQTestCase):
def test_fetching_unreadable_data(self): def test_fetching_unreadable_data(self):
"""Fetching fails on unreadable data.""" """Fetching fails on unreadable data."""
# Set up # Set up
job = Job.for_call(arbitrary_function, 3, 4, z=2) job = Job.create(arbitrary_function, 3, 4, z=2)
job.save() job.save()
# Just replace the data hkey with some random noise # Just replace the data hkey with some random noise
@ -141,7 +141,7 @@ class TestJob(RQTestCase):
job.refresh() job.refresh()
# Set up (part B) # Set up (part B)
job = Job.for_call(arbitrary_function, 3, 4, z=2) job = Job.create(arbitrary_function, 3, 4, z=2)
job.save() job.save()
# Now slightly modify the job to make it unpickl'able (this is # Now slightly modify the job to make it unpickl'able (this is

@ -85,7 +85,7 @@ class TestQueue(RQTestCase):
def test_enqueue_sets_metadata(self): def test_enqueue_sets_metadata(self):
"""Enqueueing job onto queues modifies meta data.""" """Enqueueing job onto queues modifies meta data."""
q = Queue() q = Queue()
job = Job.for_call(testjob, 'Nick', foo='bar') job = Job.create(testjob, 'Nick', foo='bar')
# Preconditions # Preconditions
self.assertIsNone(job.origin) self.assertIsNone(job.origin)
@ -195,7 +195,7 @@ class TestQueue(RQTestCase):
class TestFailedQueue(RQTestCase): class TestFailedQueue(RQTestCase):
def test_requeue_job(self): def test_requeue_job(self):
"""Requeueing existing jobs.""" """Requeueing existing jobs."""
job = Job.for_call(failing_job, 1, 2, 3) job = Job.create(failing_job, 1, 2, 3)
job.origin = 'fake' job.origin = 'fake'
job.save() job.save()
FailedQueue().quarantine(job, Exception('Some fake error')) FailedQueue().quarantine(job, Exception('Some fake error'))

@ -41,7 +41,7 @@ class TestWorker(RQTestCase):
# NOTE: We have to fake this enqueueing for this test case. # NOTE: We have to fake this enqueueing for this test case.
# What we're simulating here is a call to a function that is not # What we're simulating here is a call to a function that is not
# importable from the worker process. # importable from the worker process.
job = Job.for_call(failing_job, 3) job = Job.create(failing_job, 3)
job.save() job.save()
data = self.testconn.hget(job.key, 'data') data = self.testconn.hget(job.key, 'data')
invalid_data = data.replace('failing_job', 'nonexisting_job') invalid_data = data.replace('failing_job', 'nonexisting_job')

Loading…
Cancel
Save