Cyclium.DynamicActor.Lifecycle (Cyclium v0.1.12)

Copy Markdown View Source

Safe lifecycle operations for dynamic actors.

Provides drain-aware alternatives to Loader.stop/1 and Loader.reload/1 that wait for active episodes to complete before stopping the actor.

Usage

# Graceful drain: wait for episodes to finish, then stop
Lifecycle.drain_and_stop("my_monitor")

# Graceful reload: drain, then restart from latest DB definition
Lifecycle.drain_and_reload("my_monitor")

# Stop all with drain (for deploys)
Lifecycle.stop_all(drain: true, timeout: 30_000)

# Check active episodes
Lifecycle.active_episode_count("my_monitor")

Deploy patterns

Rolling deploy:

# In application stop callback:
Cyclium.DynamicActor.Lifecycle.stop_all(drain: true, timeout: 30_000)

Blue-green: The new instance calls Loader.load_all() on startup. Global name registration ensures only one instance runs per actor.

Summary

Functions

Returns the number of active episodes for a dynamic actor. Returns 0 if the actor is not running.

Drains a dynamic actor then reloads it from the latest DB definition.

Drains a dynamic actor (waits for active episodes to finish) then stops it.

Reloads all enabled dynamic actors.

Stops all running dynamic actors.

Functions

active_episode_count(actor_id)

Returns the number of active episodes for a dynamic actor. Returns 0 if the actor is not running.

drain_and_reload(actor_id, opts \\ [])

Drains a dynamic actor then reloads it from the latest DB definition.

Options

  • :timeout — max wait time in ms for drain (default 60000)

drain_and_stop(actor_id, opts \\ [])

Drains a dynamic actor (waits for active episodes to finish) then stops it.

Options

  • :timeout — max wait time in ms (default 60000). If exceeded, the actor is force-stopped and in-flight episodes will fail.

reload_all(opts \\ [])

Reloads all enabled dynamic actors.

Options

  • :drain — if true, drain each actor before stopping (default false)
  • :timeout — per-actor drain timeout in ms (default 60000)

stop_all(opts \\ [])

Stops all running dynamic actors.

Options

  • :drain — if true, drain each actor before stopping (default false)
  • :timeout — per-actor drain timeout in ms (default 60000)