Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli/task.py
Show First 20 Lines • Show All 380 Lines • ▼ Show 20 Lines | ): | ||||
schedule_origin_batches(scheduler, type, origin_urls, origin_batch_size, kw) | schedule_origin_batches(scheduler, type, origin_urls, origin_batch_size, kw) | ||||
@task.command("list-pending") | @task.command("list-pending") | ||||
@click.argument("task-types", required=True, nargs=-1) | @click.argument("task-types", required=True, nargs=-1) | ||||
@click.option( | @click.option( | ||||
"--limit", | "--limit", | ||||
"-l", | "-l", | ||||
"num_tasks", | |||||
required=False, | required=False, | ||||
type=click.INT, | type=click.INT, | ||||
help="The maximum number of tasks to fetch", | help="The maximum number of tasks to fetch", | ||||
) | ) | ||||
@click.option( | @click.option( | ||||
"--before", | "--before", | ||||
"-b", | "-b", | ||||
required=False, | required=False, | ||||
type=DATETIME, | 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_types, limit, before): | def list_pending_tasks(ctx, task_types, num_tasks, before): | ||||
"""List the tasks that are going to be run. | """List tasks with no priority that are going to be run. | ||||
You can override the number of tasks to fetch | You can override the number of tasks to fetch with the --limit flag. | ||||
""" | """ | ||||
from swh.scheduler import compute_nb_tasks_from | |||||
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") | ||||
num_tasks, num_tasks_priority = compute_nb_tasks_from(limit) | |||||
output = [] | output = [] | ||||
for task_type in task_types: | for task_type in task_types: | ||||
pending = scheduler.peek_ready_tasks( | pending = scheduler.peek_ready_tasks( | ||||
task_type, | task_type, timestamp=before, num_tasks=num_tasks, | ||||
timestamp=before, | |||||
num_tasks=num_tasks, | |||||
num_tasks_priority=num_tasks_priority, | |||||
) | ) | ||||
output.append("Found %d %s tasks\n" % (len(pending), task_type)) | output.append("Found %d %s tasks\n" % (len(pending), task_type)) | ||||
for task in pending: | for task in pending: | ||||
output.append(pretty_print_task(task)) | output.append(pretty_print_task(task)) | ||||
click.echo("\n".join(output)) | click.echo("\n".join(output)) | ||||
▲ Show 20 Lines • Show All 329 Lines • Show Last 20 Lines |