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[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.

  • SynchronousInvocation: 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.

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

None

__post_init__() None[source]
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
invocation_id() str
Returns:

a unique id for this invocation

A task with the same arguments can have multiple invocations, the invocation id is used to differentiate them

abstract property status: pynenc.invocation.status.InvocationStatus
abstract property result: pynenc.types.Result
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 SynchronousInvocationGroup 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__() Iterator[pynenc.invocation.base_invocation.T][source]
abstract property results: Iterator[pynenc.types.Result]

Provide an iterator over the results.

Return Iterator[Result]:

An iterator over the results of the invocations.