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
@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
keyword arguments.
"""

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

@ -32,7 +32,7 @@ class TestJob(RQTestCase):
def test_create_typical_job(self):
"""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
self.assertIsNotNone(job.id)
@ -52,7 +52,7 @@ class TestJob(RQTestCase):
def test_save(self): # noqa
"""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
self.assertEquals(self.testconn.exists(job.key), False)
@ -98,7 +98,7 @@ class TestJob(RQTestCase):
def test_persistence_of_typical_jobs(self):
"""Storing typical jobs."""
job = Job.for_call(arbitrary_function, 3, 4, z=2)
job = Job.create(arbitrary_function, 3, 4, z=2)
job.save()
expected_date = strip_milliseconds(job.created_at)
@ -113,7 +113,7 @@ class TestJob(RQTestCase):
['created_at', 'data', 'description'])
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()
job2 = Job.fetch(job.id)
@ -132,7 +132,7 @@ class TestJob(RQTestCase):
def test_fetching_unreadable_data(self):
"""Fetching fails on unreadable data."""
# Set up
job = Job.for_call(arbitrary_function, 3, 4, z=2)
job = Job.create(arbitrary_function, 3, 4, z=2)
job.save()
# Just replace the data hkey with some random noise
@ -141,7 +141,7 @@ class TestJob(RQTestCase):
job.refresh()
# 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()
# 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):
"""Enqueueing job onto queues modifies meta data."""
q = Queue()
job = Job.for_call(testjob, 'Nick', foo='bar')
job = Job.create(testjob, 'Nick', foo='bar')
# Preconditions
self.assertIsNone(job.origin)
@ -195,7 +195,7 @@ class TestQueue(RQTestCase):
class TestFailedQueue(RQTestCase):
def test_requeue_job(self):
"""Requeueing existing jobs."""
job = Job.for_call(failing_job, 1, 2, 3)
job = Job.create(failing_job, 1, 2, 3)
job.origin = 'fake'
job.save()
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.
# What we're simulating here is a call to a function that is not
# importable from the worker process.
job = Job.for_call(failing_job, 3)
job = Job.create(failing_job, 3)
job.save()
data = self.testconn.hget(job.key, 'data')
invalid_data = data.replace('failing_job', 'nonexisting_job')

Loading…
Cancel
Save