Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli/origin.py
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | @click.option( | ||||
"--fields", "-f", default=None, help="Listed origin fields to print on output" | "--fields", "-f", default=None, help="Listed origin fields to print on output" | ||||
) | ) | ||||
@click.option( | @click.option( | ||||
"--with-header/--without-header", | "--with-header/--without-header", | ||||
is_flag=True, | is_flag=True, | ||||
default=True, | default=True, | ||||
help="Print the CSV header?", | help="Print the CSV header?", | ||||
) | ) | ||||
@click.argument("type", type=str) | |||||
@click.argument("count", type=int) | @click.argument("count", type=int) | ||||
@click.pass_context | @click.pass_context | ||||
def grab_next(ctx, policy: str, fields: Optional[str], with_header: bool, count: int): | def grab_next( | ||||
"""Grab the next COUNT origins to visit from the listed origins table.""" | ctx, policy: str, fields: Optional[str], with_header: bool, type: str, count: int | ||||
): | |||||
"""Grab the next COUNT origins to visit using the TYPE loader from the | |||||
listed origins table.""" | |||||
if fields: | if fields: | ||||
parsed_fields: Optional[List[str]] = fields.split(",") | parsed_fields: Optional[List[str]] = fields.split(",") | ||||
else: | else: | ||||
parsed_fields = None | parsed_fields = None | ||||
scheduler = ctx.obj["scheduler"] | scheduler = ctx.obj["scheduler"] | ||||
origins = scheduler.grab_next_visits(count, policy=policy) | origins = scheduler.grab_next_visits(type, count, policy=policy) | ||||
for line in format_origins(origins, fields=parsed_fields, with_header=with_header): | for line in format_origins(origins, fields=parsed_fields, with_header=with_header): | ||||
click.echo(line) | click.echo(line) | ||||
@origin.command("schedule-next") | @origin.command("schedule-next") | ||||
@click.option( | @click.option( | ||||
"--policy", "-p", default="oldest_scheduled_first", help="Scheduling policy" | "--policy", "-p", default="oldest_scheduled_first", help="Scheduling policy" | ||||
) | ) | ||||
@click.argument("type", type=str) | |||||
@click.argument("count", type=int) | @click.argument("count", type=int) | ||||
@click.pass_context | @click.pass_context | ||||
def schedule_next(ctx, policy: str, count: int): | def schedule_next(ctx, policy: str, type: str, count: int): | ||||
"""Send the next COUNT origin visits to the scheduler as one-shot tasks.""" | """Send the next COUNT origin visits of the TYPE loader to the scheduler as | ||||
one-shot tasks.""" | |||||
from ..utils import utcnow | from ..utils import utcnow | ||||
from .task import pretty_print_task | from .task import pretty_print_task | ||||
scheduler = ctx.obj["scheduler"] | scheduler = ctx.obj["scheduler"] | ||||
origins = scheduler.grab_next_visits(count, policy=policy) | origins = scheduler.grab_next_visits(type, count, policy=policy) | ||||
created = scheduler.create_tasks( | created = scheduler.create_tasks( | ||||
[ | [ | ||||
{ | { | ||||
**origin.as_task_dict(), | **origin.as_task_dict(), | ||||
"policy": "oneshot", | "policy": "oneshot", | ||||
"next_run": utcnow(), | "next_run": utcnow(), | ||||
"retries_left": 1, | "retries_left": 1, | ||||
Show All 10 Lines |