|
|
@ -1,6 +1,7 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
|
|
|
|
from rq.serializers import JSONSerializer
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
import queue
|
|
|
|
import queue
|
|
|
|
import zlib
|
|
|
|
import zlib
|
|
|
@ -596,9 +597,9 @@ class TestJob(RQTestCase):
|
|
|
|
Wthout a save, the dependent job is never saved into redis. The delete
|
|
|
|
Wthout a save, the dependent job is never saved into redis. The delete
|
|
|
|
method will get and pass a NoSuchJobError.
|
|
|
|
method will get and pass a NoSuchJobError.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
queue = Queue(connection=self.testconn)
|
|
|
|
queue = Queue(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job, serializer=JSONSerializer)
|
|
|
|
job2.register_dependency()
|
|
|
|
job2.register_dependency()
|
|
|
|
|
|
|
|
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
@ -614,49 +615,49 @@ class TestJob(RQTestCase):
|
|
|
|
def test_job_delete_removes_itself_from_registries(self):
|
|
|
|
def test_job_delete_removes_itself_from_registries(self):
|
|
|
|
"""job.delete() should remove itself from job registries"""
|
|
|
|
"""job.delete() should remove itself from job registries"""
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.FAILED,
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.FAILED,
|
|
|
|
connection=self.testconn, origin='default')
|
|
|
|
connection=self.testconn, origin='default', serializer=JSONSerializer)
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
registry = FailedJobRegistry(connection=self.testconn)
|
|
|
|
registry = FailedJobRegistry(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
registry.add(job, 500)
|
|
|
|
registry.add(job, 500)
|
|
|
|
|
|
|
|
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
|
|
|
|
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.FINISHED,
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.FINISHED,
|
|
|
|
connection=self.testconn, origin='default')
|
|
|
|
connection=self.testconn, origin='default', serializer=JSONSerializer)
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
|
|
|
|
|
|
|
|
registry = FinishedJobRegistry(connection=self.testconn)
|
|
|
|
registry = FinishedJobRegistry(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
registry.add(job, 500)
|
|
|
|
registry.add(job, 500)
|
|
|
|
|
|
|
|
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
|
|
|
|
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.STARTED,
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.STARTED,
|
|
|
|
connection=self.testconn, origin='default')
|
|
|
|
connection=self.testconn, origin='default', serializer=JSONSerializer)
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
|
|
|
|
|
|
|
|
registry = StartedJobRegistry(connection=self.testconn)
|
|
|
|
registry = StartedJobRegistry(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
registry.add(job, 500)
|
|
|
|
registry.add(job, 500)
|
|
|
|
|
|
|
|
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
|
|
|
|
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.DEFERRED,
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.DEFERRED,
|
|
|
|
connection=self.testconn, origin='default')
|
|
|
|
connection=self.testconn, origin='default', serializer=JSONSerializer)
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
|
|
|
|
|
|
|
|
registry = DeferredJobRegistry(connection=self.testconn)
|
|
|
|
registry = DeferredJobRegistry(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
registry.add(job, 500)
|
|
|
|
registry.add(job, 500)
|
|
|
|
|
|
|
|
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
self.assertFalse(job in registry)
|
|
|
|
|
|
|
|
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.SCHEDULED,
|
|
|
|
job = Job.create(func=fixtures.say_hello, status=JobStatus.SCHEDULED,
|
|
|
|
connection=self.testconn, origin='default')
|
|
|
|
connection=self.testconn, origin='default', serializer=JSONSerializer)
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
|
|
|
|
|
|
|
|
registry = ScheduledJobRegistry(connection=self.testconn)
|
|
|
|
registry = ScheduledJobRegistry(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
registry.add(job, 500)
|
|
|
|
registry.add(job, 500)
|
|
|
|
|
|
|
|
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
@ -665,9 +666,9 @@ class TestJob(RQTestCase):
|
|
|
|
def test_job_with_dependents_delete_parent_with_saved(self):
|
|
|
|
def test_job_with_dependents_delete_parent_with_saved(self):
|
|
|
|
"""job.delete() deletes itself from Redis but not dependents. If the
|
|
|
|
"""job.delete() deletes itself from Redis but not dependents. If the
|
|
|
|
dependent job was saved, it will remain in redis."""
|
|
|
|
dependent job was saved, it will remain in redis."""
|
|
|
|
queue = Queue(connection=self.testconn)
|
|
|
|
queue = Queue(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job, serializer=JSONSerializer)
|
|
|
|
job2.register_dependency()
|
|
|
|
job2.register_dependency()
|
|
|
|
job2.save()
|
|
|
|
job2.save()
|
|
|
|
|
|
|
|
|
|
|
@ -683,10 +684,10 @@ class TestJob(RQTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def test_job_with_dependents_deleteall(self):
|
|
|
|
def test_job_with_dependents_deleteall(self):
|
|
|
|
"""job.delete() deletes itself from Redis. Dependents need to be
|
|
|
|
"""job.delete() deletes itself from Redis. Dependents need to be
|
|
|
|
deleted explictely."""
|
|
|
|
deleted explicitly."""
|
|
|
|
queue = Queue(connection=self.testconn)
|
|
|
|
queue = Queue(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job, serializer=JSONSerializer)
|
|
|
|
job2.register_dependency()
|
|
|
|
job2.register_dependency()
|
|
|
|
|
|
|
|
|
|
|
|
job.delete(delete_dependents=True)
|
|
|
|
job.delete(delete_dependents=True)
|
|
|
@ -701,9 +702,9 @@ class TestJob(RQTestCase):
|
|
|
|
deleted explictely. Without a save, the dependent job is never saved
|
|
|
|
deleted explictely. Without a save, the dependent job is never saved
|
|
|
|
into redis. The delete method will get and pass a NoSuchJobError.
|
|
|
|
into redis. The delete method will get and pass a NoSuchJobError.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
queue = Queue(connection=self.testconn)
|
|
|
|
queue = Queue(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job)
|
|
|
|
job2 = Job.create(func=fixtures.say_hello, depends_on=job, serializer=JSONSerializer)
|
|
|
|
job2.register_dependency()
|
|
|
|
job2.register_dependency()
|
|
|
|
job2.save()
|
|
|
|
job2.save()
|
|
|
|
|
|
|
|
|
|
|
@ -729,9 +730,9 @@ class TestJob(RQTestCase):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
job.delete() deletes itself from Redis.
|
|
|
|
job.delete() deletes itself from Redis.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
queue = Queue(connection=self.testconn)
|
|
|
|
queue = Queue(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
dependency_job = queue.enqueue(fixtures.say_hello)
|
|
|
|
dependency_job = queue.enqueue(fixtures.say_hello)
|
|
|
|
dependent_job = Job.create(func=fixtures.say_hello, depends_on=dependency_job)
|
|
|
|
dependent_job = Job.create(func=fixtures.say_hello, depends_on=dependency_job, serializer=JSONSerializer)
|
|
|
|
|
|
|
|
|
|
|
|
dependent_job.register_dependency()
|
|
|
|
dependent_job.register_dependency()
|
|
|
|
dependent_job.save()
|
|
|
|
dependent_job.save()
|
|
|
@ -811,6 +812,14 @@ class TestJob(RQTestCase):
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
|
self.assertNotIn(job, registry)
|
|
|
|
self.assertNotIn(job, registry)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_and_cancel_job_with_serializer(self):
|
|
|
|
|
|
|
|
"""test creating and using cancel_job (with serializer) deletes job properly"""
|
|
|
|
|
|
|
|
queue = Queue(connection=self.testconn, serializer=JSONSerializer)
|
|
|
|
|
|
|
|
job = queue.enqueue(fixtures.say_hello)
|
|
|
|
|
|
|
|
self.assertEqual(1, len(queue.get_jobs()))
|
|
|
|
|
|
|
|
cancel_job(job.id, serializer=JSONSerializer)
|
|
|
|
|
|
|
|
self.assertEqual(0, len(queue.get_jobs()))
|
|
|
|
|
|
|
|
|
|
|
|
def test_dependents_key_for_should_return_prefixed_job_id(self):
|
|
|
|
def test_dependents_key_for_should_return_prefixed_job_id(self):
|
|
|
|
"""test redis key to store job dependents hash under"""
|
|
|
|
"""test redis key to store job dependents hash under"""
|
|
|
|
job_id = 'random'
|
|
|
|
job_id = 'random'
|
|
|
|