pynenc.invocation.base_invocation

Module Contents

Classes

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.BaseInvocation(call: pynenc.call.Call[pynenc.types.Params, pynenc.types.Result], invocation_id: pynenc.identifiers.invocation_id.InvocationId | 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.

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.

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

Get the call associated with this invocation.

property invocation_id: pynenc.identifiers.invocation_id.InvocationId
property app: pynenc.app.Pynenc
property task: pynenc.task.Task[pynenc.types.Params, pynenc.types.Result]
property arguments: pynenc.arguments.Arguments
abstract property workflow: pynenc.workflow.workflow_identity.WorkflowIdentity
abstract property status: pynenc.invocation.status.InvocationStatus
abstract property result: pynenc.types.Result
abstractmethod 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 (dict[InvocationId, BaseInvocation]) – A dictionary of invocations, each an instance of a BaseInvocation subclass.

task: pynenc.task.Task

None

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

None

invocation_map() dict[pynenc.identifiers.invocation_id.InvocationId, pynenc.invocation.base_invocation.T]
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.

abstractmethod 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]