add django command to manage rq jobs
This commit is contained in:
parent
0c699aa7dc
commit
4584fefc08
2 changed files with 40 additions and 0 deletions
19
common/management/commands/delete_job.py
Normal file
19
common/management/commands/delete_job.py
Normal file
|
@ -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}'))
|
21
common/management/commands/list_jobs.py
Normal file
21
common/management/commands/list_jobs.py
Normal file
|
@ -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}')
|
Loading…
Add table
Reference in a new issue