Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli.py
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | lines = [ | ||||
pretty_print_list(task['arguments']['args'], indent=4), | pretty_print_list(task['arguments']['args'], indent=4), | ||||
click.style(' Keyword args:\n', bold=True), | click.style(' Keyword args:\n', bold=True), | ||||
pretty_print_dict(task['arguments']['kwargs'], indent=4), | pretty_print_dict(task['arguments']['kwargs'], indent=4), | ||||
] | ] | ||||
return ''.join(lines) | return ''.join(lines) | ||||
def list_task_types(ctx, param, value): | |||||
if not value or ctx.resilient_parsing: | |||||
return | |||||
click.echo("Known task types:") | |||||
for tasktype in ctx.obj.get_task_types(): | |||||
click.echo('{type}:\n {description}'.format(**tasktype)) | |||||
ctx.exit() | |||||
@click.group(context_settings=CONTEXT_SETTINGS) | @click.group(context_settings=CONTEXT_SETTINGS) | ||||
@click.option('--cls', '-c', default='local', | @click.option('--cls', '-c', default='local', | ||||
help="Scheduler's class, default to 'local'") | help="Scheduler's class, default to 'local'") | ||||
@click.option('--database', '-d', | @click.option('--database', '-d', | ||||
help='Scheduling database DSN') | help='Scheduling database DSN') | ||||
@click.option('--url', '-u', | @click.option('--url', '-u', | ||||
help="(Optional) Scheduler's url access") | help="(Optional) Scheduler's url access") | ||||
@click.pass_context | @click.pass_context | ||||
Show All 17 Lines | elif cls == 'remote': | ||||
scheduler = get_scheduler(cls, args=override_config) | scheduler = get_scheduler(cls, args=override_config) | ||||
if not scheduler: | if not scheduler: | ||||
raise ValueError('Scheduler class (local/remote) must be instantiated') | raise ValueError('Scheduler class (local/remote) must be instantiated') | ||||
ctx.obj = scheduler | ctx.obj = scheduler | ||||
@cli.group('task') | @cli.group('task') | ||||
@click.option('--list-types', '-l', is_flag=True, default=False, is_eager=True, | |||||
olasd: For consistency, shouldn't this be a task subcommand (or a subcommand for a new task-type group… | |||||
expose_value=False, callback=list_task_types) | |||||
@click.pass_context | @click.pass_context | ||||
def task(ctx): | def task(ctx): | ||||
"""Manipulate tasks.""" | """Manipulate tasks.""" | ||||
pass | pass | ||||
@task.command('schedule') | @task.command('schedule') | ||||
@click.option('--columns', '-c', multiple=True, | @click.option('--columns', '-c', multiple=True, | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def schedule_tasks(ctx, columns, delimiter, file): | ||||
for task in created: | for task in created: | ||||
output.append(pretty_print_task(task)) | output.append(pretty_print_task(task)) | ||||
click.echo_via_pager('\n'.join(output)) | click.echo_via_pager('\n'.join(output)) | ||||
@task.command('list-pending') | @task.command('list-pending') | ||||
@click.option('--task-type', '-t', required=True, | @click.option('--task-type', '-t', required=True, | ||||
help='The tasks\' type concerned by the listing') | help='The tasks\' type concerned by the listing') | ||||
Not Done Inline ActionsYes! olasd: Yes! | |||||
@click.option('--limit', '-l', required=False, type=click.INT, | @click.option('--limit', '-l', required=False, type=click.INT, | ||||
help='The maximum number of tasks to fetch') | help='The maximum number of tasks to fetch') | ||||
@click.option('--before', '-b', required=False, type=DATETIME, | @click.option('--before', '-b', required=False, type=DATETIME, | ||||
help='List all jobs supposed to run before the given date') | help='List all jobs supposed to run before the given date') | ||||
@click.pass_context | @click.pass_context | ||||
def list_pending_tasks(ctx, task_type, limit, before): | def list_pending_tasks(ctx, task_type, limit, before): | ||||
"""List the tasks that are going to be run. | """List the tasks that are going to be run. | ||||
You can override the number of tasks to fetch | You can override the number of tasks to fetch | ||||
""" | """ | ||||
num_tasks, num_tasks_priority = compute_nb_tasks_from(limit) | num_tasks, num_tasks_priority = compute_nb_tasks_from(limit) | ||||
Done Inline Actionsthat docstring should probably be saying --policy ? olasd: that docstring should probably be saying --policy ? | |||||
pending = ctx.obj.peek_ready_tasks( | pending = ctx.obj.peek_ready_tasks( | ||||
task_type, timestamp=before, | task_type, timestamp=before, | ||||
num_tasks=num_tasks, num_tasks_priority=num_tasks_priority) | num_tasks=num_tasks, num_tasks_priority=num_tasks_priority) | ||||
output = [ | output = [ | ||||
'Found %d tasks\n' % len(pending) | 'Found %d tasks\n' % len(pending) | ||||
] | ] | ||||
for task in pending: | for task in pending: | ||||
output.append(pretty_print_task(task)) | output.append(pretty_print_task(task)) | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |
For consistency, shouldn't this be a task subcommand (or a subcommand for a new task-type group that would allow manipulating task types)?
In any case, this doesn't list tasks, it lists task types, so if it stays here the long option name should be changed (to list-types?).