Liking cljdoc? Tell your friends :D

ottla.worker

A worker fetches and handles one consumer group's records, a batch at a time, on a thread of its own. It knows nothing about where wake-ups come from: a consumer wakes it from a listener's notifications and from a poll schedule.

Wake-ups coalesce: at most one is queued behind the batch in progress, and a newer one replaces it. A batch that comes back full queues another fetch straight away, since there are likely more records; in :manual commit mode, only if the handler committed some of it.

Only one worker per group is active at a time. Each worker keeps a connection of its own (an ottla.connection, which it replaces if it breaks), and fetches only while that connection's session holds the group's advisory lock (see ottla.postgresql/try-lock-subscription). The other workers in the group are standbys: on each wake-up they try the lock, and the first to get it once the active worker's session ends takes over. Since the lock and the fetches share a session, a worker that loses its connection loses the lock along with it, and can't fetch without it.

A worker fetches and handles one consumer group's records, a batch at a
time, on a thread of its own. It knows nothing about where wake-ups come
from: a consumer wakes it from a listener's notifications and from a
poll schedule.

Wake-ups coalesce: at most one is queued behind the batch in progress,
and a newer one replaces it. A batch that comes back full queues another
fetch straight away, since there are likely more records; in `:manual`
commit mode, only if the handler committed some of it.

Only one worker per group is active at a time. Each worker keeps a
connection of its own (an `ottla.connection`, which it replaces if it
breaks), and fetches only while that connection's session holds the
group's advisory lock (see
`ottla.postgresql/try-lock-subscription`). The other workers in the group
are standbys: on each wake-up they try the lock, and the first to get it
once the active worker's session ends takes over. Since the lock and the
fetches share a session, a worker that loses its connection loses the
lock along with it, and can't fetch without it.
raw docstring

default-exception-handlerclj

(default-exception-handler e)
source

IWorkercljprotocol

wake!clj

(wake! worker max-eid)

Queue a fetch of records up to max-eid (nil for no upper bound). Does nothing once the worker is shut down.

Queue a fetch of records up to `max-eid` (nil for no upper bound).
Does nothing once the worker is shut down.
source

start-workerclj

(start-worker config
              {:keys [topic] :as basic-selection}
              handler
              {:keys [xform exception-handler await-close-ms max-records
                      on-shutdown thread-name reconnect-ms]
               worker-conn-map :conn-map
               :or {await-close-ms 1000
                    exception-handler default-exception-handler
                    xform identity
                    max-records 100
                    reconnect-ms 2000
                    on-shutdown (fn [])
                    thread-name "ottla-worker"}
               :as opts})

Connect, ensure the subscription for selection exists, and start a worker that runs handler on its records whenever it's its group's active worker.

The worker keeps a connection of its own, opened from the :conn-map option, or the config's :conn-map (never its :conn), for the group's lock and for fetching and handling. If the connection breaks, the worker reconnects on a later wake-up, no sooner than :reconnect-ms after, and comes back as a standby.

Options are the consumer's fetch and handle options (:deserialize-key, :deserialize-value, :xform, :max-records, :exception-handler, :await-close-ms, :conn-map, :reconnect-ms), plus:

  • :on-shutdown (fn []) called after the worker shuts itself down because the exception handler returned :ottla/shutdown
  • :thread-name names the worker's thread
Connect, ensure the subscription for `selection` exists, and start a
worker that runs `handler` on its records whenever it's its group's
active worker.

The worker keeps a connection of its own, opened from the `:conn-map`
option, or the config's `:conn-map` (never its `:conn`), for the group's
lock and for fetching and handling. If the connection breaks, the worker
reconnects on a later wake-up, no sooner than `:reconnect-ms` after,
and comes back as a standby.

Options are the consumer's fetch and handle options (`:deserialize-key`,
`:deserialize-value`, `:xform`, `:max-records`, `:exception-handler`,
`:await-close-ms`, `:conn-map`, `:reconnect-ms`), plus:
  - `:on-shutdown` (fn []) called after the worker shuts itself down
    because the exception handler returned `:ottla/shutdown`
  - `:thread-name` names the worker's thread
sourceraw docstring

with-commit-modecljmacro

(with-commit-mode [conn commit-mode] & body)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close