Avoid using use_connection, initial queues directly using redis connection

main
zhangliyong 10 years ago
parent adc24b6fe0
commit c90da5336e

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

@ -9,7 +9,7 @@ import click
from functools import partial
from redis.exceptions import ConnectionError
from rq import Queue, Worker
from rq import Queue, Worker, use_connection
red = partial(click.style, fg='red')
@ -155,12 +155,15 @@ def refresh(val, func, *args):
@click.option('--only-workers', '-W', is_flag=True, help='Show only worker info') # noqa
@click.option('--by-queue', '-R', is_flag=True, help='Shows workers by queue') # noqa
@click.argument('queues', nargs=-1)
def info(path, interval, raw, only_queues, only_workers, by_queue, queues):
@click.pass_context
def info(ctx, path, interval, raw, only_queues, only_workers, by_queue, queues):
"""RQ command-line monitor."""
if path:
sys.path = path.split(':') + sys.path
conn = ctx.obj['connection']
use_connection(conn)
try:
if only_queues:
func = show_queues

Loading…
Cancel
Save