diff options
author | Vincent Driessen <vincent@3rdcloud.com> | 2014-09-06 08:25:03 +0200 |
---|---|---|
committer | Vincent Driessen <vincent@3rdcloud.com> | 2014-09-06 08:42:56 +0200 |
commit | 5c96c6125512c9baa352d83cf3eed3d42fce49f6 (patch) | |
tree | 0ccc7b37e8452bfb2419bdb3a87a3f7676d6921d | |
parent | 07dda7471002062c69dac4a3f6ab8c808565a9f3 (diff) | |
download | rq-zhangliyong-cli-rq.tar.gz |
Change `rq requeue` subtly, mostly docs and vars.zhangliyong-cli-rq
-rwxr-xr-x | rq/scripts/rq_cli.py | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/rq/scripts/rq_cli.py b/rq/scripts/rq_cli.py index 1d77ec4..8e0490a 100755 --- a/rq/scripts/rq_cli.py +++ b/rq/scripts/rq_cli.py @@ -5,6 +5,8 @@ RQ command line tool from __future__ import (absolute_import, division, print_function, unicode_literals) +import sys + import click import redis from rq import get_failed_queue, Queue @@ -47,40 +49,32 @@ def empty(ctx, all, queues): @main.command() -@click.option('--all', '-a', 'is_all', is_flag=True, help='Requeue all failed jobs') +@click.option('--all', '-a', is_flag=True, help='Requeue all failed jobs') @click.argument('job_ids', nargs=-1) @click.pass_context -def requeue(ctx, is_all, job_ids): - """[JOB_IDS] Job_ids in FailedQueue to requeue - - \b - $ rq requeue -a - Requeueing 10 jobs from FailedQueue - [####################################] 100% - Unable to requeue 0 jobs from FailedQueue - - \b - $ rq requeue a28bd044-65f3-42dd-96ee-acfcea155ba7\ - ac5559e1-90a0-4ab5-8e68-0d854b47b969 - Requeueing 2 jobs from FailedQueue - [####################################] 100% - Unable to requeue 1 jobs from FailedQueue - """ +def requeue(ctx, all, job_ids): + """Requeue failed jobs.""" conn = ctx.obj['connection'] failed_queue = get_failed_queue(connection=conn) - if not job_ids and is_all: + + if all: job_ids = failed_queue.job_ids - click.echo('Requeueing {0} jobs from FailedQueue'.format(len(job_ids))) - requeue_failed_num = 0 - with click.progressbar(job_ids) as job_bar: - for job_id in job_bar: + + if not job_ids: + click.echo('Nothing to do') + sys.exit(0) + + click.echo('Requeueing {0} jobs from failed queue'.format(len(job_ids))) + fail_count = 0 + with click.progressbar(job_ids) as job_ids: + for job_id in job_ids: try: failed_queue.requeue(job_id) except InvalidJobOperationError: - requeue_failed_num += 1 + fail_count += 1 - click.secho('Unable to requeue {0} jobs from FailedQueue'.format( - requeue_failed_num), fg='red') + if fail_count > 0: + click.secho('Unable to requeue {0} jobs from failed queue'.format(fail_count), fg='red') main.add_command(info) |