Ejemplo n.º 1
0
def cancel(pulp_ctx: PulpContext, task_ctx: PulpTaskContext,
           href: str) -> None:
    """Cancels a task and waits until the cancellation is confirmed."""
    entity = task_ctx.show(href)
    if entity["state"] not in ["waiting", "running"]:
        click.ClickException(
            f"Task {href} is in state {entity['state']} and cannot be canceled."
        )

    task_ctx.cancel(href)
    click.echo(f"Waiting to cancel task {href}", err=True)
    try:
        pulp_ctx.wait_for_task(entity)
    except Exception as e:
        if str(e) != "Task canceled":
            raise e
    click.echo("Done.", err=True)
Ejemplo n.º 2
0
def show(pulp_ctx: PulpContext, task_ctx: PulpTaskContext, href: str,
         wait: bool) -> None:
    """Shows details of a task."""
    entity = task_ctx.show(href)
    if wait and entity["state"] in ["waiting", "running"]:
        click.echo(f"Waiting for task {href} to finish.", err=True)
        entity = pulp_ctx.wait_for_task(entity)
    pulp_ctx.output_result(entity)
Ejemplo n.º 3
0
def show(pulp_ctx: PulpContext, task_ctx: PulpTaskContext, wait: bool) -> None:
    """Shows details of a task."""
    entity = task_ctx.entity
    if wait and entity["state"] in ["waiting", "running", "canceling"]:
        click.echo(_("Waiting for task {href} to finish.").format(
            href=task_ctx.pulp_href),
                   err=True)
        entity = pulp_ctx.wait_for_task(entity)
    pulp_ctx.output_result(entity)
Ejemplo n.º 4
0
def cancel(
    pulp_ctx: PulpContext,
    task_ctx: PulpTaskContext,
    all_tasks: bool,
    waiting_tasks: bool,
    running_tasks: bool,
) -> None:
    """Cancels a task and waits until the cancellation is confirmed."""
    states = []
    if waiting_tasks or all_tasks:
        states.append("waiting")
    if running_tasks or all_tasks:
        states.append("running")
    if states:
        tasks = task_ctx.list(limit=1 << 64,
                              offset=0,
                              parameters={"state__in": ",".join(states)})
        for task in tasks:
            with suppress(Exception):
                task_ctx.cancel(task["pulp_href"])
        for task in tasks:
            with suppress(Exception):
                pulp_ctx.wait_for_task(task)
    else:
        entity = task_ctx.entity
        if entity["state"] not in ["waiting", "running"]:
            click.ClickException(
                _("Task {href} is in state {state} and cannot be canceled.").
                format(href=task_ctx.pulp_href, state=entity["state"]))

        task_ctx.cancel(task_ctx.pulp_href)
        click.echo(
            _("Waiting to cancel task {href}").format(href=task_ctx.pulp_href),
            err=True)
        try:
            pulp_ctx.wait_for_task(entity)
        except Exception as e:
            if not re.match("Task /pulp/api/v3/tasks/[-0-9a-f]*/ canceled",
                            str(e)):
                raise e
        click.echo(_("Done."), err=True)