Ankusa.SDK.Handler behaviour (ankusa_sdk v0.6.0)

Copy Markdown View Source

What a hook consumer implements: one callback for both transports.

Return :ok only once the hook is durably handled — the same contract docs/integrations.md ("HTTP handoff") states for any receiver. Return {:error, reason} for "not handled": Ankusa.SDK.Receiver answers it with 503, so Ankusa's dispatcher retries, and a queue consumer should treat it as a requeue. A raise, or any other return value, is not rescued: the Receiver lets it surface as a 500, which Ankusa retries the same way.

defmodule MyApp.Hooks do
  @behaviour Ankusa.SDK.Handler

  @impl Ankusa.SDK.Handler
  def handle_hook(%Ankusa.SDK.Hook{} = hook, _arg) do
    case MyApp.Store.insert(hook.id, hook.body) do
      :inserted -> :ok
      :duplicate -> :ok
      {:error, reason} -> {:error, reason}
    end
  end
end

Summary

Callbacks

handle_hook(hook, arg)

@callback handle_hook(hook :: Ankusa.SDK.Hook.t(), arg :: term()) ::
  :ok | {:error, term()}