Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
Remove direct redis calls
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Jun 3, 2023
1 parent d4e7497 commit e015f81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Remove need for django-model-utils dependency
* Fix GitHub actions
* Fix security issues
* Clean direct redis connection calls from views.py

## v2023.6.0 🌈

Expand Down
6 changes: 6 additions & 0 deletions scheduler/rq_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ def clean_registries(self):
self.failed_job_registry.cleanup()
self.finished_job_registry.cleanup()

def remove_job_id(self, job_id: str):
self.connection.lrem(self.key, 0, job_id)

def last_job_id(self):
return self.connection.lindex(self.key, 0)


class DjangoScheduler(RQScheduler):
def __init__(self, *args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions scheduler/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_statistics(run_maintenance_tasks=False):
# with `at_front` parameters.
# Ideally rq should supports Queue.oldest_job

last_job_id = connection.lindex(queue.key, 0)
last_job_id = queue.last_job_id()
last_job = queue.fetch_job(last_job_id.decode('utf-8')) if last_job_id else None
if last_job and last_job.enqueued_at:
oldest_job_timestamp = last_job.enqueued_at.strftime('%Y-%m-%d, %H:%M:%S')
Expand Down Expand Up @@ -378,7 +378,7 @@ def actions(request, queue_name):
for job_id in job_ids:
job = JobExecution.fetch(job_id, connection=queue.connection)
# Remove job id from queue and delete the actual job
queue.connection.lrem(queue.key, 0, job.id)
queue.remove_job_id(job.id)
job.delete()
messages.info(request, f'You have successfully deleted {len(job_ids)} jobs!')
elif action == 'requeue':
Expand Down Expand Up @@ -429,7 +429,7 @@ def job_action(request, job_id: str, action: str):
return redirect('job_details', job_id)
elif action == 'delete':
# Remove job id from queue and delete the actual job
queue.connection.lrem(queue.key, 0, job.id)
queue.remove_job_id(job.id)
job.delete()
messages.info(request, 'You have successfully deleted %s' % job.id)
return redirect('queue_registry_jobs', queue.name, 'queued')
Expand Down

0 comments on commit e015f81

Please sign in to comment.