Packages

Vertical slicing for Elixir — features as self-contained slices using event sourcing and CQRS

Current section

Files

Jump to
counterpoint lib counterpoint queue oban.ex
Raw

lib/counterpoint/queue/oban.ex

if Code.ensure_loaded?(Oban) do
defmodule Counterpoint.Queue.Oban do
@behaviour Counterpoint.Queue
@impl Counterpoint.Queue
def enqueue(automation_module, envelope) do
args = encode_envelope(automation_module, envelope)
args
|> Counterpoint.Queue.Oban.Worker.new()
|> Oban.insert()
end
defp encode_envelope(automation_module, envelope) do
%{
"automation_module" => inspect(automation_module),
"type" => envelope.type,
"tags" => envelope.tags,
"data" => envelope.data.__struct__.to_map(envelope.data),
"position" => Base.encode64(envelope.position),
"occurred_at" =>
if(envelope.occurred_at, do: DateTime.to_iso8601(envelope.occurred_at), else: nil)
}
end
end
end