|
|
|
@ -88,9 +88,9 @@ class TestJob(RQTestCase):
|
|
|
|
|
"""Fetching jobs."""
|
|
|
|
|
# Prepare test
|
|
|
|
|
self.testconn.hset('rq:job:some_id', 'data',
|
|
|
|
|
"(S'tests.fixtures.some_calculation'\nN(I3\nI4\nt(dp1\nS'z'\nI2\nstp2\n.") # noqa
|
|
|
|
|
"(S'tests.fixtures.some_calculation'\nN(I3\nI4\nt(dp1\nS'z'\nI2\nstp2\n.")
|
|
|
|
|
self.testconn.hset('rq:job:some_id', 'created_at',
|
|
|
|
|
"2012-02-07 22:13:24+0000")
|
|
|
|
|
'2012-02-07 22:13:24+0000')
|
|
|
|
|
|
|
|
|
|
# Fetch returns a job
|
|
|
|
|
job = Job.fetch('some_id')
|
|
|
|
@ -110,13 +110,13 @@ class TestJob(RQTestCase):
|
|
|
|
|
expected_date = strip_milliseconds(job.created_at)
|
|
|
|
|
stored_date = self.testconn.hget(job.key, 'created_at').decode('utf-8')
|
|
|
|
|
self.assertEquals(
|
|
|
|
|
times.to_universal(stored_date),
|
|
|
|
|
expected_date)
|
|
|
|
|
times.to_universal(stored_date),
|
|
|
|
|
expected_date)
|
|
|
|
|
|
|
|
|
|
# ... and no other keys are stored
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.testconn.hkeys(job.key),
|
|
|
|
|
[b'created_at'])
|
|
|
|
|
self.testconn.hkeys(job.key),
|
|
|
|
|
[b'created_at'])
|
|
|
|
|
|
|
|
|
|
def test_persistence_of_typical_jobs(self):
|
|
|
|
|
"""Storing typical jobs."""
|
|
|
|
@ -126,13 +126,13 @@ class TestJob(RQTestCase):
|
|
|
|
|
expected_date = strip_milliseconds(job.created_at)
|
|
|
|
|
stored_date = self.testconn.hget(job.key, 'created_at').decode('utf-8')
|
|
|
|
|
self.assertEquals(
|
|
|
|
|
times.to_universal(stored_date),
|
|
|
|
|
expected_date)
|
|
|
|
|
times.to_universal(stored_date),
|
|
|
|
|
expected_date)
|
|
|
|
|
|
|
|
|
|
# ... and no other keys are stored
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
sorted(self.testconn.hkeys(job.key)),
|
|
|
|
|
[b'created_at', b'data', b'description'])
|
|
|
|
|
sorted(self.testconn.hkeys(job.key)),
|
|
|
|
|
[b'created_at', b'data', b'description'])
|
|
|
|
|
|
|
|
|
|
def test_store_then_fetch(self):
|
|
|
|
|
"""Store, then fetch."""
|
|
|
|
@ -195,14 +195,27 @@ class TestJob(RQTestCase):
|
|
|
|
|
"""Ensure that job's result_ttl is set properly"""
|
|
|
|
|
job = Job.create(func=say_hello, args=('Lionel',), result_ttl=10)
|
|
|
|
|
job.save()
|
|
|
|
|
job_from_queue = Job.fetch(job.id, connection=self.testconn)
|
|
|
|
|
Job.fetch(job.id, connection=self.testconn)
|
|
|
|
|
self.assertEqual(job.result_ttl, 10)
|
|
|
|
|
|
|
|
|
|
job = Job.create(func=say_hello, args=('Lionel',))
|
|
|
|
|
job.save()
|
|
|
|
|
job_from_queue = Job.fetch(job.id, connection=self.testconn)
|
|
|
|
|
Job.fetch(job.id, connection=self.testconn)
|
|
|
|
|
self.assertEqual(job.result_ttl, None)
|
|
|
|
|
|
|
|
|
|
def test_description_is_persisted(self):
|
|
|
|
|
"""Ensure that job's custom description is set properly"""
|
|
|
|
|
job = Job.create(func=say_hello, args=('Lionel',), description=u'Say hello!')
|
|
|
|
|
job.save()
|
|
|
|
|
Job.fetch(job.id, connection=self.testconn)
|
|
|
|
|
self.assertEqual(job.description, u'Say hello!')
|
|
|
|
|
|
|
|
|
|
# Ensure job description is constructed from function call string
|
|
|
|
|
job = Job.create(func=say_hello, args=('Lionel',))
|
|
|
|
|
job.save()
|
|
|
|
|
Job.fetch(job.id, connection=self.testconn)
|
|
|
|
|
self.assertEqual(job.description, "tests.fixtures.say_hello('Lionel')")
|
|
|
|
|
|
|
|
|
|
def test_job_access_within_job_function(self):
|
|
|
|
|
"""The current job is accessible within the job function."""
|
|
|
|
|
# Executing the job function from outside of RQ throws an exception
|
|
|
|
@ -240,12 +253,12 @@ class TestJob(RQTestCase):
|
|
|
|
|
"""Test that jobs and results are expired properly."""
|
|
|
|
|
job = Job.create(func=say_hello)
|
|
|
|
|
job.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Jobs with negative TTLs don't expire
|
|
|
|
|
job.cleanup(ttl=-1)
|
|
|
|
|
self.assertEqual(self.testconn.ttl(job.key), -1)
|
|
|
|
|
|
|
|
|
|
# Jobs with positive TTLs are eventually deleted
|
|
|
|
|
# Jobs with positive TTLs are eventually deleted
|
|
|
|
|
job.cleanup(ttl=100)
|
|
|
|
|
self.assertEqual(self.testconn.ttl(job.key), 100)
|
|
|
|
|
|
|
|
|
|