Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli.py
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | def schedule_tasks(ctx, columns, delimiter, file): | ||||
click.echo_via_pager('\n'.join(output)) | click.echo_via_pager('\n'.join(output)) | ||||
@task.command('add') | @task.command('add') | ||||
@click.argument('type', nargs=1, required=True) | @click.argument('type', nargs=1, required=True) | ||||
@click.argument('options', nargs=-1) | @click.argument('options', nargs=-1) | ||||
@click.option('--policy', '-p', default='recurring', | @click.option('--policy', '-p', default='recurring', | ||||
type=click.Choice(['recurring', 'oneshot'])) | type=click.Choice(['recurring', 'oneshot'])) | ||||
@click.option('--priority', '-P', default='low', | |||||
type=click.Choice(['low', 'normal', 'high'])) | |||||
ardumont: None is actually a value too.
currently, recurring by default do not have a priority at all. | |||||
ardumontUnsubmitted Not Done Inline Actionsrecurring tasks* ardumont: recurring tasks* | |||||
ardumontUnsubmitted Not Done Inline ActionsTo match the actual behavior, as the policy default to recurring, the default of priority matching is None. ardumont: To match the actual behavior, as the policy default to recurring, the default of priority… | |||||
@click.option('--next-run', '-n', default=None) | @click.option('--next-run', '-n', default=None) | ||||
@click.pass_context | @click.pass_context | ||||
def schedule_task(ctx, type, options, policy, next_run): | def schedule_task(ctx, type, options, policy, priority, next_run): | ||||
"""Schedule one task from arguments. | """Schedule one task from arguments. | ||||
Use sample: | Use sample: | ||||
swh-scheduler --database 'service=swh-scheduler' \ | swh-scheduler --database 'service=swh-scheduler' \ | ||||
task add swh-lister-pypi | task add swh-lister-pypi | ||||
swh-scheduler --database 'service=swh-scheduler' \ | swh-scheduler --database 'service=swh-scheduler' \ | ||||
task add swh-lister-debian --policy=oneshot distribution=stretch | task add swh-lister-debian --policy=oneshot distribution=stretch | ||||
""" | """ | ||||
scheduler = ctx.obj['scheduler'] | scheduler = ctx.obj['scheduler'] | ||||
if not scheduler: | if not scheduler: | ||||
raise ValueError('Scheduler class (local/remote) must be instantiated') | raise ValueError('Scheduler class (local/remote) must be instantiated') | ||||
now = arrow.utcnow() | now = arrow.utcnow() | ||||
args = [x for x in options if '=' not in x] | args = [x for x in options if '=' not in x] | ||||
kw = dict(x.split('=', 1) for x in options if '=' in x) | kw = dict(x.split('=', 1) for x in options if '=' in x) | ||||
task = {'type': type, | task = {'type': type, | ||||
'policy': policy, | 'policy': policy, | ||||
'priority': priority, | |||||
'arguments': { | 'arguments': { | ||||
'args': args, | 'args': args, | ||||
'kwargs': kw, | 'kwargs': kw, | ||||
}, | }, | ||||
'next_run': DATETIME.convert(next_run or now, | 'next_run': DATETIME.convert(next_run or now, | ||||
None, None), | None, None), | ||||
} | } | ||||
created = scheduler.create_tasks([task]) | created = scheduler.create_tasks([task]) | ||||
▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines |
None is actually a value too.
currently, recurring by default do not have a priority at all.