Mob.Wake.Registry (mob_wake v0.1.2)

Copy Markdown View Source

ETS-backed dispatch table for mob_wake.

Owns the identifier → {trigger, mfa, state} table used by Mob.Wake.register/2, Mob.Wake.dispatch/1, and Mob.Wake.status/1.

Reads go directly to ETS (public, read-concurrency on) so dispatch/1 is fast on the hot path. Writes go through the GenServer so registration is serialised and can validate opts. State updates (:last_fired_at, :state) after each dispatch go through the GenServer too — one owner keeps the concurrent-write story simple.

This module is @moduledoc false-adjacent — it's public for the plugin's own supervision tree but users should reach for Mob.Wake, not touch this directly.

Seeded at start from Application.get_env(:mob_wake, :tasks, []) — the compile-time task table each host declares in mob.exs.

Summary

Types

A registered task: {identifier, trigger, mfa, state}.

Functions

All currently registered tasks.

Returns a specification to start this module under a supervisor.

Look up a registered task.

Register or replace a task's identifier → MFA mapping.

Start the registry, seeding from config :mob_wake, :tasks.

Update a task's :state, :last_fired_at, :next_eligible_fire fields.

Types

entry()

@type entry() ::
  {atom(), MobWake.trigger(), {module(), atom()} | {module(), atom(), [any()]},
   map()}

A registered task: {identifier, trigger, mfa, state}.

  • identifier — the atom the OS-side handler names when it fires.
  • trigger — :refresh | :processing | :push.

  • mfa — {module, function} or {module, function, extra_args}. extra_args is prepended to the invocation's dispatch payload.
  • state — mutable per-entry metadata (:state, :last_fired_at, :next_eligible_fire) updated after each dispatch.

Functions

all()

@spec all() :: [entry()]

All currently registered tasks.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

lookup(identifier)

@spec lookup(atom()) :: {:ok, entry()} | :error

Look up a registered task.

Direct ETS read — safe on the hot path from concurrent processes. Returns {:ok, entry} or :error.

put(identifier, trigger, mfa)

@spec put(atom(), MobWake.trigger(), {module(), atom()} | {module(), atom(), [any()]}) ::
  :ok

Register or replace a task's identifier → MFA mapping.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the registry, seeding from config :mob_wake, :tasks.

update_state(identifier, changes)

@spec update_state(atom(), map()) :: :ok | {:error, :unknown_identifier}

Update a task's :state, :last_fired_at, :next_eligible_fire fields.