Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli/task.py
Show First 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | @click.option( | ||||
help="Also list past executions of each task.", | help="Also list past executions of each task.", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def list_tasks( | def list_tasks( | ||||
ctx, task_id, task_type, limit, status, policy, priority, before, after, list_runs | ctx, task_id, task_type, limit, status, policy, priority, before, after, list_runs | ||||
): | ): | ||||
"""List tasks. | """List tasks. | ||||
""" | """ | ||||
from operator import itemgetter | |||||
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") | ||||
if not task_type: | if not task_type: | ||||
task_type = [x["type"] for x in scheduler.get_task_types()] | task_type = [x["type"] for x in scheduler.get_task_types()] | ||||
# if task_id is not given, default value for status is | # if task_id is not given, default value for status is | ||||
Show All 21 Lines | ): | ||||
if list_runs: | if list_runs: | ||||
runs = {t["id"]: [] for t in tasks} | runs = {t["id"]: [] for t in tasks} | ||||
for r in scheduler.get_task_runs([task["id"] for task in tasks]): | for r in scheduler.get_task_runs([task["id"] for task in tasks]): | ||||
runs[r["task"]].append(r) | runs[r["task"]].append(r) | ||||
else: | else: | ||||
runs = {} | runs = {} | ||||
output.append("Found %d tasks\n" % (len(tasks))) | output.append("Found %d tasks\n" % (len(tasks))) | ||||
for task in tasks: | for task in sorted(tasks, key=itemgetter("id")): | ||||
output.append(pretty_print_task(task, full=True)) | output.append(pretty_print_task(task, full=True)) | ||||
if runs.get(task["id"]): | if runs.get(task["id"]): | ||||
output.append(click.style(" Executions:", bold=True)) | output.append(click.style(" Executions:", bold=True)) | ||||
for run in runs[task["id"]]: | for run in sorted(runs[task["id"]], key=itemgetter("id")): | ||||
output.append(pretty_print_run(run, indent=4)) | output.append(pretty_print_run(run, indent=4)) | ||||
click.echo("\n".join(output)) | click.echo("\n".join(output)) | ||||
@task.command("respawn") | @task.command("respawn") | ||||
@click.argument("task-ids", required=True, nargs=-1) | @click.argument("task-ids", required=True, nargs=-1) | ||||
@click.option( | @click.option( | ||||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |