MingaAgent.EventLog (Minga v0.1.0)

Copy Markdown View Source

Durable append-only event log for agent sessions.

Agent sessions call record/3, which is a cast to this writer process, so session execution never waits on SQLite I/O. Readers open their own connections through open_read_connection/1 and query by cursor with events_after/4; WAL mode lets those reads proceed without blocking the writer.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the configured event-log database path.

Queries events for a session after the given cursor.

Returns the latest event id for a session.

Opens a read connection to the agent event database.

Starts the event log writer.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

db_path(opts \\ [])

@spec db_path(keyword()) :: String.t()

Returns the configured event-log database path.

events_after(db, session_id, last_id, limit \\ 1000)

@spec events_after(
  MingaAgent.EventLog.Store.db(),
  String.t(),
  non_neg_integer(),
  pos_integer()
) ::
  {:ok, [MingaAgent.EventLog.EventRecord.t()]} | {:error, term()}

Queries events for a session after the given cursor.

latest_id(db, session_id)

@spec latest_id(MingaAgent.EventLog.Store.db(), String.t()) ::
  {:ok, non_neg_integer()} | {:error, term()}

Returns the latest event id for a session.

open_read_connection(opts \\ [])

@spec open_read_connection(keyword()) ::
  {:ok, MingaAgent.EventLog.Store.db()} | {:error, term()}

Opens a read connection to the agent event database.

record(session_id, event_type, payload \\ %{}, server \\ __MODULE__)

Records an agent event asynchronously.

start_link(opts \\ [])

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

Starts the event log writer.