pynenc.invocation.base_invocation

Module Contents

Classes

InvocationIdentity

Immutable identity of an invocation

BaseInvocation

Base class for representing an invocation of a task call in a distributed system.

BaseInvocationGroup

Abstract base class for grouping multiple invocations of a specific task.

Data

T

API

pynenc.invocation.base_invocation.T

‘TypeVar(…)’

class pynenc.invocation.base_invocation.InvocationIdentity[source]

Bases: typing.Generic[pynenc.types.Params, pynenc.types.Result]

Immutable identity of an invocation

call: pynenc.call.Call[pynenc.types.Params, pynenc.types.Result]

None

invocation_id: str

‘field(…)’

parent_invocation: BaseInvocation | None

None

class pynenc.invocation.base_invocation.BaseInvocation(call: pynenc.call.Call[pynenc.types.Params, pynenc.types.Result], parent_invocation: pynenc.invocation.base_invocation.BaseInvocation | None = None, invocation_id: str | None = None, workflow: pynenc.workflow.identity.WorkflowIdentity | None = None)[source]

Bases: abc.ABC, typing.Generic[pynenc.types.Params, pynenc.types.Result]

Base class for representing an invocation of a task call in a distributed system.

In the context of the system, the following concepts are key:

  • Function: A standard Python function.

  • Task: A Pynenc object encapsulating a function, enabling it to run in a distributed environment. Tasks are unique by module and function name and cannot be nested.

  • Call: A specific call to a task with a set of arguments, unique per function and argument set.

  • Invocation: A specific execution instance of a call.

A single task can be called with different arguments, and each call can be executed multiple times. This distinction is crucial for orchestration and cycle control within the system.

The BaseInvocation class serves as a template for two key types of invocations:

  • DistributedInvocation: The primary invocation type used in the system for distributed execution.

  • ConcurrentInvocation: Used for local execution, primarily in testing environments without a runner.

Important

Sync invocations cannot be used in production environments, only for testing in sync mode.

Parameters:

call (Call[Params, Result]) – The specific call instance that this invocation represents.

Initialization

Initialize the invocation with its identity.

init_logger() None[source]

Initialize the logger for the invocation.

is_main_workflow_task() bool[source]

Check if the task is the main workflow task.

Returns:

True if the task is the main workflow task, False otherwise

Note

All tasks run within a workflow, the main workflow task is just the first task in the workflow.
To determine that, we check if the task_id of the workflow task is the same as the task_id of the current task.
property call: pynenc.call.Call[pynenc.types.Params, pynenc.types.Result]
property invocation_id: str
property parent_invocation: pynenc.invocation.base_invocation.BaseInvocation | None
property app: pynenc.app.Pynenc
property task: pynenc.task.Task[pynenc.types.Params, pynenc.types.Result]
property arguments: pynenc.arguments.Arguments
property serialized_arguments: dict[str, str]
abstract to_json() str[source]
Returns:

The serialized invocation

abstract classmethod from_json(app: pynenc.app.Pynenc, serialized: str) pynenc.invocation.base_invocation.T[source]
Returns:

a new invocation from a serialized invocation

property call_id: str
abstract property status: pynenc.invocation.status.InvocationStatus
abstract property result: pynenc.types.Result
abstract async async_result() pynenc.types.Result[source]
abstract property num_retries: int
__str__() str[source]
__repr__() str[source]
__hash__() int[source]
__eq__(other: Any) bool[source]
class pynenc.invocation.base_invocation.BaseInvocationGroup[source]

Bases: abc.ABC, typing.Generic[pynenc.types.Params, pynenc.types.Result, pynenc.invocation.base_invocation.T]

Abstract base class for grouping multiple invocations of a specific task.

This class is designed to aggregate a collection of invocations, each represented by a BaseInvocation or its subclasses. It is useful in scenarios where multiple invocations of a task need to be managed or processed together.

Subclasses of BaseInvocationGroup, such as ConcurrentInvocationGroup and DistributedInvocationGroup, provide specific implementations for synchronous and distributed environments, respectively.

Parameters:
  • task (Task) – The task associated with the invocations.

  • invocations (list[BaseInvocation]) – A list of invocations, each an instance of a BaseInvocation subclass.

task: pynenc.task.Task

None

invocations: list[pynenc.invocation.base_invocation.T]

None

property app: pynenc.app.Pynenc
__iter__() collections.abc.Iterator[pynenc.invocation.base_invocation.T][source]
abstract property results: collections.abc.Iterator[pynenc.types.Result]

Provide an iterator over the results.

Return Iterator[Result]:

An iterator over the results of the invocations.

abstract async_results() collections.abc.AsyncGenerator[pynenc.types.Result, None][source]

An async iterator over the results of the invocations in the group.

This method asynchronously iterates over the ConcurrentInvocation instances, yielding the result of each invocation using their async_result method.

Returns:

An async iterator over the results of each invocation in the group.

Return type:

AsyncIterator[Result]