Merge pull request #600 from glaslos/cancel_remove

Cancel and Delete differences
main
Selwin Ong 9 years ago
commit 8bbd833855

@ -467,23 +467,21 @@ class Job(object):
This method merely exists as a high-level API call to cancel jobs This method merely exists as a high-level API call to cancel jobs
without worrying about the internals required to implement job without worrying about the internals required to implement job
cancellation. Technically, this call is (currently) the same as just cancellation.
deleting the job hash.
""" """
from .queue import Queue from .queue import Queue
pipeline = self.connection._pipeline() pipeline = self.connection._pipeline()
self.delete(pipeline=pipeline)
pipeline.delete(self.dependents_key)
if self.origin: if self.origin:
queue = Queue(name=self.origin, connection=self.connection) queue = Queue(name=self.origin, connection=self.connection)
queue.remove(self, pipeline=pipeline) queue.remove(self, pipeline=pipeline)
pipeline.execute() pipeline.execute()
def delete(self, pipeline=None): def delete(self, pipeline=None):
"""Deletes the job hash from Redis.""" """Cancels the job and deletes the job hash from Redis."""
self.cancel()
connection = pipeline if pipeline is not None else self.connection connection = pipeline if pipeline is not None else self.connection
connection.delete(self.key) connection.delete(self.key)
connection.delete(self.dependents_key)
# Job execution # Job execution
def perform(self): # noqa def perform(self): # noqa
@ -538,7 +536,7 @@ class Job(object):
forever) forever)
""" """
if ttl == 0: if ttl == 0:
self.cancel() self.delete()
elif not ttl: elif not ttl:
return return
elif ttl > 0: elif ttl > 0:

@ -378,13 +378,13 @@ class TestJob(RQTestCase):
self.assertEqual(as_text(self.testconn.spop('rq:job:id:dependents')), job.id) self.assertEqual(as_text(self.testconn.spop('rq:job:id:dependents')), job.id)
self.assertEqual(registry.get_job_ids(), [job.id]) self.assertEqual(registry.get_job_ids(), [job.id])
def test_cancel(self): def test_delete(self):
"""job.cancel() deletes itself & dependents mapping from Redis.""" """job.delete() deletes itself & dependents mapping from Redis."""
queue = Queue(connection=self.testconn) queue = Queue(connection=self.testconn)
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)
job2.register_dependency() job2.register_dependency()
job.cancel() job.delete()
self.assertFalse(self.testconn.exists(job.key)) self.assertFalse(self.testconn.exists(job.key))
self.assertFalse(self.testconn.exists(job.dependents_key)) self.assertFalse(self.testconn.exists(job.dependents_key))

@ -88,10 +88,8 @@ class TestQueue(RQTestCase):
job = q.enqueue(say_hello) job = q.enqueue(say_hello)
self.assertEqual(q.jobs, [job]) self.assertEqual(q.jobs, [job])
# Fetching a deleted removes it from queue # Deleting job removes it from queue
job.delete() job.delete()
self.assertEqual(q.job_ids, [job.id])
q.jobs
self.assertEqual(q.job_ids, []) self.assertEqual(q.job_ids, [])
def test_compact(self): def test_compact(self):

Loading…
Cancel
Save