From 07dda7471002062c69dac4a3f6ab8c808565a9f3 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Sat, 6 Sep 2014 08:18:18 +0200 Subject: [PATCH] Change options of the `rq empty` command. * Does not ask confirmation * Does not need `--yes` option anymore * Added --all, to clear all queues * No implicit emptying of the failed queue. If you want to empty the failed queue, just use `$ rq empty failed` --- rq/scripts/rq_cli.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/rq/scripts/rq_cli.py b/rq/scripts/rq_cli.py index 4ebab61..1d77ec4 100755 --- a/rq/scripts/rq_cli.py +++ b/rq/scripts/rq_cli.py @@ -27,33 +27,23 @@ def main(ctx, url): @main.command() -@click.option('--yes', '-y', is_flag=True, help='Empty failed queue by default') +@click.option('--all', '-a', is_flag=True, help='Empty all queues') @click.argument('queues', nargs=-1) @click.pass_context -def empty(ctx, yes, queues): - """[QUEUES]: queues to empty - - \b - $ rq empty - Do you want to empty failed queue? [y/N]: y - 2 jobs removed from failed queue - \b - $ rq empty -y - 2 jobs removed from failed queue - \b - $ rq empty default high - 10 jobs removed from default queue - 2 jobs removed from high queue - """ +def empty(ctx, all, queues): + """Empty given queues.""" conn = ctx.obj['connection'] - queues = [Queue(queue, connection=conn) for queue in queues] + if all: + queues = Queue.all(connection=conn) + else: + queues = [Queue(queue, connection=conn) for queue in queues] + if not queues: - if yes or click.confirm('Do you want to empty failed queue?', abort=True): - queues = (get_failed_queue(connection=conn),) + click.echo('Nothing to do') + for queue in queues: num_jobs = queue.empty() - click.echo('{0} jobs removed from {1} queue'.format( - num_jobs, queue.name)) + click.echo('{0} jobs removed from {1} queue'.format(num_jobs, queue.name)) @main.command()