Temper.Push.Acknowledgements (temper v0.4.0)

Copy Markdown View Source

The runs a push destination has accepted, kept next to the history so CI caches them with it: one file per destination, pushed-runs-<id>, one run id per line. <id> is a short hash of the destination (the adapter and its Temper.Push.Adapter.destination_key/2), so pointing the task somewhere else starts from nothing instead of skipping runs the new destination never saw.

mix temper.push reads it to send only new runs, and adds the run ids of every accepted batch. Ids of runs no longer in the history are dropped as it is written (unless part of the history could not be read), so the file shrinks with the history. A lost file only means the next push resends everything, which a destination applying each run once skips.

merge/3 and file_name/2 are pure; read/1 and record/3 touch the file.

Summary

Functions

The file name for the destination adapter with config.

existing followed by the ids of new not already in it, keeping only ids in history (all of them when history is nil).

The accepted run ids, or an empty set when there is no file yet.

Adds run_ids to the file and keeps only the ids in history (a MapSet of the run ids the history holds now), or every id when history is nil (part of the history could not be read, so absent ids may still be there). The file is replaced atomically: written to a new file beside it (created exclusively, so an existing file or link there is never written through), then renamed over it.

Functions

file_name(adapter, config)

@spec file_name(
  module(),
  keyword()
) :: String.t()

The file name for the destination adapter with config.

merge(existing, new, history)

@spec merge([String.t()], [String.t()], MapSet.t(String.t()) | nil) :: [String.t()]

existing followed by the ids of new not already in it, keeping only ids in history (all of them when history is nil).

read(path)

@spec read(Path.t()) :: MapSet.t(String.t())

The accepted run ids, or an empty set when there is no file yet.

record(path, run_ids, history)

@spec record(Path.t(), [String.t()], MapSet.t(String.t()) | nil) ::
  :ok | {:error, File.posix()}

Adds run_ids to the file and keeps only the ids in history (a MapSet of the run ids the history holds now), or every id when history is nil (part of the history could not be read, so absent ids may still be there). The file is replaced atomically: written to a new file beside it (created exclusively, so an existing file or link there is never written through), then renamed over it.