Honker (honker v0.1.4)

Copy Markdown

Elixir binding for Honker — a SQLite-native task runtime.

This module is a thin wrapper around the Honker loadable extension. Each public function is one SQL call via Exqlite.Sqlite3; state lives in the .db file, not in Elixir processes.

Example

{:ok, db} = Honker.open("app.db", extension_path: "./libhonker_ext.dylib")

Honker.Queue.enqueue(db, "emails", %{to: "alice@example.com"})

case Honker.Queue.claim_one(db, "emails", "worker-1") do
  {:ok, nil} -> :empty
  {:ok, job} ->
    send_email(job.payload)
    Honker.Job.ack(db, job)
end

A Honker.Database struct is the handle; it wraps an Exqlite.Sqlite3 reference + the queue's default options (visibility timeout, max attempts). Use configure_queue/3 to override per-queue.

Summary

Functions

Set the options for a named queue (visibility timeout, max attempts). Stored in the handle; Queue.enqueue/claim reads them.

Fetch a stored result. Returns {:ok, value} or {:ok, nil} when absent or expired.

Fire a pg_notify-style pub/sub signal. Returns {:ok, id}.

Fire a notification inside an open transaction. The notification row only becomes visible to listeners after the transaction commits.

Open (or create) a SQLite database at path. Loads the Honker extension from extension_path, applies default PRAGMAs, and bootstraps the schema.

Return a transactional outbox handle backed by _outbox:<name>.

Delete notifications older than older_than_s seconds. Returns {:ok, count_deleted}.

Persist a job result for later retrieval via get_result/2. value must be a string — encode JSON yourself if you want structure. ttl_s is seconds before sweep_results/1 will delete it.

Delete expired results. Returns {:ok, count_deleted}.

Fixed-window rate limit. Returns {:ok, true} if the caller fits in limit per per seconds, {:ok, false} if blocked.

Functions

close(database)

configure_queue(db, queue_name, opts)

Set the options for a named queue (visibility timeout, max attempts). Stored in the handle; Queue.enqueue/claim reads them.

Defaults: visibility_timeout_s = 300, max_attempts = 3.

get_result(database, job_id)

Fetch a stored result. Returns {:ok, value} or {:ok, nil} when absent or expired.

notify(database, channel, payload)

Fire a pg_notify-style pub/sub signal. Returns {:ok, id}.

notify_tx(transaction, channel, payload)

Fire a notification inside an open transaction. The notification row only becomes visible to listeners after the transaction commits.

open(path, opts)

Open (or create) a SQLite database at path. Loads the Honker extension from extension_path, applies default PRAGMAs, and bootstraps the schema.

:watcher_backend is implemented by honker-core through the loaded Honker extension. It accepts the same aliases as the other bindings: nil, "", "poll", "polling", "kernel", "kernel-watcher", "shm", and "shm-fast-path".

:watcher_poll_interval_ms raises the default 1 ms update watcher cadence when lower idle CPU matters more than lowest-latency wakeups.

outbox(db, name, delivery, opts \\ [])

Return a transactional outbox handle backed by _outbox:<name>.

prune_notifications(database, older_than_s)

Delete notifications older than older_than_s seconds. Returns {:ok, count_deleted}.

save_result(database, job_id, value, ttl_s)

Persist a job result for later retrieval via get_result/2. value must be a string — encode JSON yourself if you want structure. ttl_s is seconds before sweep_results/1 will delete it.

sweep_results(database)

Delete expired results. Returns {:ok, count_deleted}.

try_rate_limit(database, name, limit, per)

Fixed-window rate limit. Returns {:ok, true} if the caller fits in limit per per seconds, {:ok, false} if blocked.