Skip to content

Elixir binding

The Elixir binding loads Knocker’s SQLite extension through exqlite and exposes the shared receive, worker, operator, and retention contract.

The package is currently repo-local. Build the extension first:

Terminal window
cargo build --release -p knocker-extension

Install dependencies once:

Terminal window
make test-elixir-setup
{:ok, opened} = KnockerSqlite.open("app.db")
webhooks =
KnockerSqlite.register_handler(opened, "automation", "invoice.created", fn event, _tx ->
IO.inspect(event["id"], label: "handled")
end)
{:ok, _endpoint_id} =
KnockerSqlite.add_endpoint(webhooks, %{
name: "automation",
path: "/webhooks/automation",
provider: "token-header",
enabled: true
})
{:ok, result} =
KnockerSqlite.receive(webhooks, %{
endpoint: "automation",
provider: "token-header",
secrets: ["dev-secret"],
body: ~s({"id":"evt_1","type":"invoice.created"}),
headers: %{"X-Knocker-Token" => "dev-secret"}
})
1 = KnockerSqlite.run_worker(webhooks, "elixir-worker", %{max_jobs: 1})
IO.inspect(result["status_code"])

receive(...) delegates provider verification to the Rust/SQLite knocker_receive(...) path. run_worker(...) runs handlers later against stored SQLite rows and rolls handler writes back before retry/dead-letter bookkeeping when the handler returns an error.

Terminal window
make test-elixir