Chronicle.EventSequences.AppendResult (cratis_chronicle v3.16.1)

Copy Markdown View Source

The detailed outcome of an append, mirroring the .NET client's AppendResult / AppendManyResult.

Returned by Chronicle.EventSequences.EventLog.append_with_result/3 and append_many_with_result/3, which return {:ok, result} when the append succeeded and {:error, result} when the kernel rejected it - so a rejection can be inspected instead of being collapsed into an opaque term.

  • :sequence_numbers - the sequence numbers assigned to the appended events, in order (empty when nothing was appended or the kernel did not assign any)
  • :sequence_number - the first of those, or nil
  • :correlation_id - the correlation id of the append
  • :constraint_violations - list of constraint_violation/0
  • :concurrency_violations - list of concurrency_violation/0
  • :errors - list of error messages

Summary

Functions

The Chronicle.Events.EventContext-free helper: whether any violation was reported.

Waits for every observer affected by the appended events to reach the last appended sequence number or fail. Mirrors .NET's AppendResult.WaitForCompletion().

Types

concurrency_violation()

@type concurrency_violation() :: %{
  event_source_id: String.t(),
  expected_sequence_number: non_neg_integer(),
  actual_sequence_number: non_neg_integer()
}

constraint_violation()

@type constraint_violation() :: %{
  constraint_name: String.t(),
  message: String.t(),
  event_type_id: String.t(),
  sequence_number: non_neg_integer(),
  details: %{optional(String.t()) => String.t()}
}

t()

@type t() :: %Chronicle.EventSequences.AppendResult{
  client: atom(),
  concurrency_violations: [concurrency_violation()],
  constraint_violations: [constraint_violation()],
  correlation_id: String.t(),
  errors: [String.t()],
  event_sequence_id: String.t(),
  namespace: String.t() | nil,
  sequence_number: non_neg_integer() | nil,
  sequence_numbers: [non_neg_integer()],
  success?: boolean()
}

Functions

rejected?(result)

@spec rejected?(t()) :: boolean()

The Chronicle.Events.EventContext-free helper: whether any violation was reported.

wait_for_completion(result, opts)

@spec wait_for_completion(t(), keyword()) :: {:ok, map()} | {:error, term()}

Waits for every observer affected by the appended events to reach the last appended sequence number or fail. Mirrors .NET's AppendResult.WaitForCompletion().

Options: :timeout (milliseconds). Returns {:ok, %{success: boolean(), failed_partitions: [...]}}.