|
|
@ -8,7 +8,7 @@ from __future__ import (absolute_import, division, print_function,
|
|
|
|
|
|
|
|
|
|
|
|
import click
|
|
|
|
import click
|
|
|
|
import redis
|
|
|
|
import redis
|
|
|
|
from rq import get_failed_queue, Queue, use_connection
|
|
|
|
from rq import get_failed_queue, Queue
|
|
|
|
from rq.exceptions import InvalidJobOperationError
|
|
|
|
from rq.exceptions import InvalidJobOperationError
|
|
|
|
|
|
|
|
|
|
|
|
from .rqinfo import info
|
|
|
|
from .rqinfo import info
|
|
|
@ -17,16 +17,21 @@ from .rqinfo import info
|
|
|
|
@click.group()
|
|
|
|
@click.group()
|
|
|
|
@click.option('--url', '-u', envvar='URL',
|
|
|
|
@click.option('--url', '-u', envvar='URL',
|
|
|
|
help='URL describing Redis connection details.')
|
|
|
|
help='URL describing Redis connection details.')
|
|
|
|
def main(url):
|
|
|
|
@click.pass_context
|
|
|
|
|
|
|
|
def main(ctx, url):
|
|
|
|
|
|
|
|
"""Entrance of RQ CLI"""
|
|
|
|
if url is None:
|
|
|
|
if url is None:
|
|
|
|
url = "redis://localhost:6379/0"
|
|
|
|
url = "redis://localhost:6379/0"
|
|
|
|
redis_conn = redis.from_url(url)
|
|
|
|
redis_conn = redis.from_url(url)
|
|
|
|
use_connection(redis_conn)
|
|
|
|
|
|
|
|
|
|
|
|
ctx.obj = {}
|
|
|
|
|
|
|
|
ctx.obj['connection'] = redis_conn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.command()
|
|
|
|
@main.command()
|
|
|
|
@click.argument('queues', nargs=-1)
|
|
|
|
@click.argument('queues', nargs=-1)
|
|
|
|
def empty(queues):
|
|
|
|
@click.pass_context
|
|
|
|
|
|
|
|
def empty(ctx, queues):
|
|
|
|
"""[QUEUES]: queues to empty, default: failed queue
|
|
|
|
"""[QUEUES]: queues to empty, default: failed queue
|
|
|
|
|
|
|
|
|
|
|
|
\b
|
|
|
|
\b
|
|
|
@ -37,18 +42,21 @@ def empty(queues):
|
|
|
|
10 jobs removed from default queue
|
|
|
|
10 jobs removed from default queue
|
|
|
|
2 jobs removed from high queue
|
|
|
|
2 jobs removed from high queue
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
queues = list(map(Queue, queues))
|
|
|
|
conn = ctx.obj['connection']
|
|
|
|
|
|
|
|
queues = [Queue(queue, connection=conn) for queue in queues]
|
|
|
|
if not queues:
|
|
|
|
if not queues:
|
|
|
|
queues = (get_failed_queue(),)
|
|
|
|
queues = (get_failed_queue(connection=conn),)
|
|
|
|
for queue in queues:
|
|
|
|
for queue in queues:
|
|
|
|
num_jobs = queue.empty()
|
|
|
|
num_jobs = queue.empty()
|
|
|
|
click.echo('{} jobs removed from {} queue'.format(num_jobs, queue.name))
|
|
|
|
click.echo('{} jobs removed from {} queue'.format(num_jobs, queue.name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.command()
|
|
|
|
@main.command()
|
|
|
|
def requeue():
|
|
|
|
@click.pass_context
|
|
|
|
|
|
|
|
def requeue(ctx):
|
|
|
|
"""Requeue all failed jobs in failed queue"""
|
|
|
|
"""Requeue all failed jobs in failed queue"""
|
|
|
|
failed_queue = get_failed_queue()
|
|
|
|
conn = ctx.obj['connection']
|
|
|
|
|
|
|
|
failed_queue = get_failed_queue(connection=conn)
|
|
|
|
job_ids = failed_queue.job_ids
|
|
|
|
job_ids = failed_queue.job_ids
|
|
|
|
click.echo('Requeue failed jobs: {}'.format(len(job_ids)))
|
|
|
|
click.echo('Requeue failed jobs: {}'.format(len(job_ids)))
|
|
|
|
requeue_failed_num = 0
|
|
|
|
requeue_failed_num = 0
|
|
|
|