Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix job deletion from a registry after manual enqueening #665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions django_rq/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,31 +539,40 @@ def actions(request, queue_index):
@never_cache
@staff_member_required
def enqueue_job(request, queue_index, job_id):
"""Enqueue deferred jobs"""
"""Enqueue deferred/scheduled/finished jobs"""
queue_index = int(queue_index)
queue = get_queue_by_index(queue_index)
job = Job.fetch(job_id, connection=queue.connection, serializer=queue.serializer)

if request.method == 'POST':
try:
# _enqueue_job is new in RQ 1.14, this is used to enqueue
# job regardless of its dependencies
queue._enqueue_job(job)
except AttributeError:
queue.enqueue_job(job)

# Remove job from correct registry if needed
if job.get_status() == JobStatus.DEFERRED:
registry = DeferredJobRegistry(queue.name, queue.connection)
registry.remove(job)
elif job.get_status() == JobStatus.FINISHED:
registry = FinishedJobRegistry(queue.name, queue.connection)
registry.remove(job)
elif job.get_status() == JobStatus.SCHEDULED:
registry = ScheduledJobRegistry(queue.name, queue.connection)
job_status = job.get_status()

if job_status in {
JobStatus.DEFERRED,
JobStatus.SCHEDULED,
JobStatus.FINISHED,
}:
try:
# _enqueue_job is new in RQ 1.14, this is used to enqueue
# job regardless of its dependencies
queue._enqueue_job(job)
except AttributeError:
queue.enqueue_job(job)

# Remove job from correct registry
RegistryClass = {
JobStatus.DEFERRED: DeferredJobRegistry,
JobStatus.SCHEDULED: ScheduledJobRegistry,
JobStatus.FINISHED: FinishedJobRegistry,
}[job_status]

registry = RegistryClass(queue.name, queue.connection)
registry.remove(job)

messages.info(request, 'You have successfully enqueued %s' % job.id)
messages.info(request, 'You have successfully enqueued %s' % job.id)
else:
messages.error(request, 'Failed to enqueue %s. Only deferred/scheduled/finished jobs can be enqueued.' % job_id)

return redirect('rq_job_detail', queue_index, job_id)

context_data = {
Expand Down
Loading