diff --git a/common/management/commands/delete_job.py b/common/management/commands/delete_job.py new file mode 100644 index 00000000..1c1d6c86 --- /dev/null +++ b/common/management/commands/delete_job.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand +import pprint +from redis import Redis +from rq.job import Job +from rq import Queue + + +class Command(BaseCommand): + help = 'Delete a job' + + def add_arguments(self, parser): + parser.add_argument('job_id', type=str, help='Job ID') + + def handle(self, *args, **options): + redis = Redis() + job_id = str(options['job_id']) + job = Job.fetch(job_id, connection=redis) + job.delete() + self.stdout.write(self.style.SUCCESS(f'Deleted {job}')) diff --git a/common/management/commands/list_jobs.py b/common/management/commands/list_jobs.py new file mode 100644 index 00000000..76c3165a --- /dev/null +++ b/common/management/commands/list_jobs.py @@ -0,0 +1,21 @@ +from django.core.management.base import BaseCommand +import pprint +from redis import Redis +from rq.job import Job +from rq import Queue + + +class Command(BaseCommand): + help = 'Show jobs in queue' + + def add_arguments(self, parser): + parser.add_argument('queue', type=str, help='Queue') + + def handle(self, *args, **options): + redis = Redis() + queue = Queue(str(options['queue']), connection=redis) + for registry in [queue.started_job_registry, queue.deferred_job_registry, queue.finished_job_registry, queue.failed_job_registry, queue.scheduled_job_registry]: + self.stdout.write(self.style.SUCCESS(f'Registry {registry}')) + for job_id in registry.get_job_ids(): + job = Job.fetch(job_id, connection=redis) + print(f'Job {job}')