WardrikEvents.Log (wardrik_events v0.1.0-rc.1)

Copy Markdown

Reads and writes one log: an agent's kept events in a store, in order, each under its sequence number.

An index lists every log.

Summary

Functions

Writes event at the log's next sequence number. Returns the event with its sequence.

Returns the sequence number of the log's last event. If every event was dropped, returns the last dropped one's.

Returns the logs whose names start with prefix.

Returns the oldest sequence number the log holds. If it holds none, returns the next one it will write.

Returns up to limit events after the sequence number after_sequence.

Drops the log's events written before cutoff.

Functions

append(store, heads, log, event)

Writes event at the log's next sequence number. Returns the event with its sequence.

last(store, log)

@spec last(WardrikStore.t(), String.t()) :: non_neg_integer()

Returns the sequence number of the log's last event. If every event was dropped, returns the last dropped one's.

logs(store, prefix \\ "")

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

Returns the logs whose names start with prefix.

oldest(store, log)

@spec oldest(WardrikStore.t(), String.t()) :: pos_integer()

Returns the oldest sequence number the log holds. If it holds none, returns the next one it will write.

read(store, log, after_sequence, limit)

@spec read(WardrikStore.t(), String.t(), non_neg_integer(), non_neg_integer()) ::
  {:ok, [WardrikEvents.CloudEvent.t()]} | {:dropped, pos_integer()}

Returns up to limit events after the sequence number after_sequence.

Returns {:dropped, oldest} if retention dropped the next one.

trim(store, log, cutoff)

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

Drops the log's events written before cutoff.