Skip to main content
Version: 4.2

ChildRunRegistry

Persisted name -> run map that lets named child runs survive a migration or resurrection of the parent.

Every change is written to the key-value store right away. A hard kill of the parent between the platform starting the child and that write can still orphan the child, since nothing but the platform knows about it.

Index

Methods

__init__

  • __init__(open_key_value_store): None
  • Parameters

    • open_key_value_store: Callable[[], Awaitable[KeyValueStore]]

    Returns None

abort_runs_with_parent

  • async abort_runs_with_parent(client): None
  • Gracefully abort every recorded run marked abort_with_parent, and refuse to start any more of them.

    Each run gets one abort request, all in parallel. The platform leaves a run that already finished as it is. A failure to abort one run is logged and does not stop the others. A run whose start is in flight is aborted once the start records it.


    Parameters

    • client: ApifyClientAsync

      Client used for a name not started or looked up in this process, e.g. after a migration.

    Returns None

find_or_start

  • async find_or_start(name, *, actor_id, task_id, run_input, client, start_run, resurrect_run, abort_with_parent): tuple[Run, bool]
  • Return the run recorded under name, or start one when there is none to reuse.

    A recorded run that is READY or RUNNING is reattached and one that SUCCEEDED is returned as is. An ABORTED or TIMED-OUT run is resurrected, since Actors are expected to resume from their state. A FAILED run, or one the API no longer knows, is replaced by a new run under the same name, for any Actor, task or input.


    Parameters

    • name: str

      Name of the child run, unique within the parent run.

    • optionalkeyword-onlyactor_id: str | None = None

      The Actor to start.

    • optionalkeyword-onlytask_id: str | None = None

      The task to start, in place of actor_id.

    • keyword-onlyrun_input: Any

      Input of the run. The recorded run is reused only if it was started with the same Actor or task and input.

    • keyword-onlyclient: ApifyClientAsync

      Client used to look up the recorded run.

    • keyword-onlystart_run: Callable[[], Awaitable[Run]]

      Starts a new run of the Actor or task.

    • keyword-onlyresurrect_run: Callable[[str], Awaitable[Run]]

      Resurrects the recorded run, given its ID.

    • optionalkeyword-onlyabort_with_parent: bool = False

      Whether to abort the run when this Actor run is gracefully aborted. It replaces the value recorded under name.

    Returns tuple[Run, bool]

    The run, and whether it was newly started.

load

  • Read the records from the default key-value store, replacing any read before.


    Returns dict[str, ChildRunRecord]

run_clients

  • run_clients(default_client): dict[str, RunClientAsync]
  • Return a client for the current run under each recorded name.

    Each client comes from the client its name was last started or looked up with in this process, so a run started with a custom token uses that token.


    Parameters

    • default_client: ApifyClientAsync

      Client used for a name not started or looked up in this process, e.g. one recorded before a migration.

    Returns dict[str, RunClientAsync]

update

  • async update(name, run): None
  • Record the latest observed status of the run recorded under name.


    Parameters

    • name: str

      Name of the child run.

    • run: Run

      The run as just returned by the API. Nothing is recorded unless it is the current run under name.

    Returns None