WardrikTriggers.Records (wardrik_triggers v0.1.0-rc.1)

Copy Markdown

Stores triggers. Each record holds the trigger, its next and last run, and what its feeds and webhook have seen.

Summary

Functions

Returns every stored trigger as {agent_id, name}.

Deletes trigger name of agent_id.

Returns the record for trigger name of agent_id and its version, or nil.

Returns the record's next run, or nil for a webhook.

Returns the trigger names of agent_id.

Writes record if the stored version is vsn. Pass nil to create it.

Returns the record's trigger.

Updates the record with fun. Retries on a conflicting write.

Functions

all(store)

@spec all(WardrikStore.t()) :: [{String.t(), String.t()}]

Returns every stored trigger as {agent_id, name}.

delete(store, agent_id, name)

@spec delete(WardrikStore.t(), String.t(), String.t()) :: :ok | {:error, term()}

Deletes trigger name of agent_id.

lookup(store, agent_id, name)

@spec lookup(WardrikStore.t(), String.t(), String.t()) ::
  {map(), WardrikStore.vsn()} | nil

Returns the record for trigger name of agent_id and its version, or nil.

next_at(map)

@spec next_at(map()) :: DateTime.t() | nil

Returns the record's next run, or nil for a webhook.

of(store, agent_id)

@spec of(WardrikStore.t(), String.t()) :: [String.t()]

Returns the trigger names of agent_id.

put(store, record, vsn)

@spec put(WardrikStore.t(), map(), WardrikStore.vsn() | nil) ::
  :ok | {:error, :conflict | term()}

Writes record if the stored version is vsn. Pass nil to create it.

Returns {:error, :conflict} if the version differs.

trigger(map)

@spec trigger(map()) :: WardrikTriggers.Trigger.t()

Returns the record's trigger.

update(store, agent_id, name, fun)

@spec update(WardrikStore.t(), String.t(), String.t(), (map() -> map())) ::
  :ok | {:error, term()}

Updates the record with fun. Retries on a conflicting write.

Returns {:error, :not_found} if there's no record.