View Source Actors.Actor.CallerConsumer (spawn v1.1.1)

An Elixir module representing a GenStage consumer responsible for handling events initiated by CallerProducer and interacting with actors in the system.

Summary

Functions

Performs the action of looking up or creating an actor based on the given parameters.

Gets the state of the specified actor.

Handles incoming events from the CallerProducer GenStage.

Initializes the GenStage consumer.

Invokes an actor action with distributed tracing using OpenTelemetry.

Registers actors in the system based on the provided registration request.

Spawns an actor or a group of actors based on the provided SpawnRequest.

Starts the consumer process and subscribes to the CallerProducer GenStage.

Tries to reactivate an actor.

Functions

Link to this function

do_lookup_action(system_name, actor_fqdn, system, action_fun)

View Source

Performs the action of looking up or creating an actor based on the given parameters.

This function is responsible for looking up or creating an actor based on the specified actor fully-qualified domain name (FQDN). It incorporates distributed tracing with OpenTelemetry to capture relevant events and attributes during the lookup or creation process.

Parameters

  • system_name (String): The name of the actor system.
  • actor_fqdn (tuple): A tuple representing the fully-qualified domain name (FQDN) of the actor.
  • system (%ActorSystem{}): The actor system.
  • action_fun (function): The function to be invoked once the actor is looked up or created. It receives the actor reference and actor reference ID as parameters.

Tracing Context

The function sets up a span with the name "actor-lookup" to trace the lookup or creation process. It adds relevant attributes, such as the actor FQDN, to the tracing context.

Retry Mechanism

The function incorporates a retry mechanism with backoff, randomization, and timeout to handle potential errors during the lookup or creation process.

Returns

The result of the action_fun function or an error tuple in case of failure.

Error Handling

In case of errors during the lookup or creation process, appropriate logging and tracing events are added, and the error is returned as part of the result tuple.

Gets the state of the specified actor.

This function attempts to retrieve the state of the actor identified by the given ActorId. It uses an exponential backoff strategy for retrying in case of errors and logs any failures.

Parameters

  • id (%ActorId): The unique identifier of the actor.

Returns

The state of the actor if successful, otherwise an error is raised.

Retry Strategy

The function utilizes an exponential backoff strategy with randomized delays and a maximum expiry time of 30,000 milliseconds.

Errors

The function handles errors such as :error, :exit, :noproc, :erpc, :noconnection, and :timeout. It also rescues ErlangError exceptions and logs detailed error messages.

Link to this function

handle_events(events, from, state)

View Source

Handles incoming events from the CallerProducer GenStage.

Dispatches events to the appropriate functions for further processing.

Initializes the GenStage consumer.

It subscribes to the CallerProducer GenStage with specified backpressure values.

Link to this function

invoke_with_span(request, opts)

View Source

Invokes an actor action with distributed tracing using OpenTelemetry.

This function performs an actor action invocation, incorporating distributed tracing with OpenTelemetry. It sets up the tracing context, adds relevant attributes, and handles asynchronous and synchronous invocations.

Parameters

  • request (%InvocationRequest): The request containing information about the invocation.
  • opts (Keyword.t): Additional options for the invocation. Defaults to an empty keyword list.

Returns

A tuple containing the status and the result of the invocation. If the invocation is asynchronous, it returns {:ok, :async}.

Tracing Context

The function sets up the tracing context and adds attributes related to the invocation. It uses OpenTelemetry to trace the client invoke with the kind set to :client.

Retry Mechanism

The function incorporates a retry mechanism with backoff, randomization, and timeout to handle potential errors during the invocation.

Error Handling

In case of errors during the invocation, appropriate logging and tracing events are added, and the error is re-raised with a stack trace.

Link to this function

register(registration, opts)

View Source

Registers actors in the system based on the provided registration request.

Handles registration requests and ensures actors are properly registered.

Link to this function

spawn_actor(spawn, opts \\ [])

View Source

Spawns an actor or a group of actors based on the provided SpawnRequest.

This function is responsible for spawning actors based on the specified SpawnRequest. It retrieves the hosts associated with the provided actor IDs and registers the actors. Additionally, it handles cases where the system is in the process of draining or stopping.

Parameters

  • spawn (%SpawnRequest): The request containing information about the actors to spawn.
  • opts (Keyword.t): Additional options for spawning the actors. Defaults to an empty keyword list.

Returns

If successful, it returns {:ok, %SpawnResponse{status: %RequestStatus{status: :OK, message: "Accepted"}}}. Otherwise, an error is raised.

Actor Spawning Process

  • Retrieves actor hosts based on actor IDs from the ActorRegistry.
  • Filters the hosts based on the system's graceful shutdown status.
  • Registers the selected hosts in the ActorRegistry.
  • Returns a success response.

Errors

  • Raises an ArgumentError if attempting to spawn an unnamed actor that has not been registered before.

Starts the consumer process and subscribes to the CallerProducer GenStage.

Link to this function

try_reactivate_actor(system, actor, opts \\ [])

View Source
@spec try_reactivate_actor(
  Eigr.Functions.Protocol.Actors.ActorSystem.t(),
  Eigr.Functions.Protocol.Actors.Actor.t(),
  any()
) :: {:ok, any()} | {:error, any()}

Tries to reactivate an actor.

Reactivation is attempted by looking up the actor in the registry or creating a new actor if not found.