|
|
@ -4,11 +4,6 @@ from __future__ import (absolute_import, division, print_function,
|
|
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
from tests import RQTestCase
|
|
|
|
|
|
|
|
from tests.fixtures import (access_self, CallableObject, Number, say_hello,
|
|
|
|
|
|
|
|
some_calculation)
|
|
|
|
|
|
|
|
from tests.helpers import strip_microseconds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from rq.compat import as_text, PY2
|
|
|
|
from rq.compat import as_text, PY2
|
|
|
|
from rq.exceptions import NoSuchJobError, UnpickleError
|
|
|
|
from rq.exceptions import NoSuchJobError, UnpickleError
|
|
|
|
from rq.job import get_current_job, Job
|
|
|
|
from rq.job import get_current_job, Job
|
|
|
@ -16,6 +11,11 @@ from rq.queue import Queue
|
|
|
|
from rq.registry import DeferredJobRegistry
|
|
|
|
from rq.registry import DeferredJobRegistry
|
|
|
|
from rq.utils import utcformat
|
|
|
|
from rq.utils import utcformat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from tests import RQTestCase
|
|
|
|
|
|
|
|
from tests.fixtures import (access_self, CallableObject, Number, say_hello,
|
|
|
|
|
|
|
|
some_calculation, long_running_job)
|
|
|
|
|
|
|
|
from tests.helpers import strip_microseconds
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from cPickle import loads, dumps
|
|
|
|
from cPickle import loads, dumps
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
@ -334,6 +334,24 @@ class TestJob(RQTestCase):
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
self.assertEqual(job.get_ttl(), None)
|
|
|
|
self.assertEqual(job.get_ttl(), None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ttl_via_enqueue(self):
|
|
|
|
|
|
|
|
ttl = 1
|
|
|
|
|
|
|
|
queue = Queue(connection=self.testconn)
|
|
|
|
|
|
|
|
job = queue.enqueue(say_hello, ttl=ttl)
|
|
|
|
|
|
|
|
self.assertEqual(job.get_ttl(), ttl)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_never_expire_during_execution(self):
|
|
|
|
|
|
|
|
"""Test what happens when job expires during execution"""
|
|
|
|
|
|
|
|
ttl = 1
|
|
|
|
|
|
|
|
queue = Queue(connection=self.testconn)
|
|
|
|
|
|
|
|
job = queue.enqueue(long_running_job, args=(2,), ttl=ttl)
|
|
|
|
|
|
|
|
self.assertEqual(job.get_ttl(), ttl)
|
|
|
|
|
|
|
|
job.save()
|
|
|
|
|
|
|
|
job.perform()
|
|
|
|
|
|
|
|
self.assertEqual(job.get_ttl(), -1)
|
|
|
|
|
|
|
|
self.assertTrue(job.exists(job.id))
|
|
|
|
|
|
|
|
self.assertEqual(job.result, 'Done sleeping...')
|
|
|
|
|
|
|
|
|
|
|
|
def test_cleanup(self):
|
|
|
|
def test_cleanup(self):
|
|
|
|
"""Test that jobs and results are expired properly."""
|
|
|
|
"""Test that jobs and results are expired properly."""
|
|
|
|
job = Job.create(func=say_hello)
|
|
|
|
job = Job.create(func=say_hello)
|
|
|
|