Liking cljdoc? Tell your friends :D

jobs

Background job processing with priority queues, scheduled execution, automatic retries with exponential backoff, and multi-tenant support.

Key namespaces

NamespacePurpose

boundary.jobs.core.job

Pure functions: job creation, state transitions, retry logic

boundary.jobs.ports

Protocols: IJobQueue, IJobStore, IJobStats, IJobWorker, IJobRegistry

boundary.jobs.schema

Malli schemas: job states, priorities, retry config

boundary.jobs.shell.adapters.in-memory

In-memory adapter (atoms, for dev/test)

boundary.jobs.shell.adapters.redis

Redis adapter (sorted sets, lists, hashes)

boundary.jobs.shell.worker

Worker implementation: polling, processing, pool management

boundary.jobs.shell.tenant-context

Multi-tenant job execution with schema switching

Handler signature

;; Handlers receive args map, return result map
(defn send-email-handler [args]
  {:success? true
   :result {:sent-to (:email args)}})

;; Failing handler
(defn failing-handler [args]
  {:success? false
   :error {:message "Processing failed" :type "ProcessingError"}})

Enqueueing jobs

(require '[boundary.jobs.core.job :as job]
         '[boundary.jobs.ports :as ports])

(let [new-job (job/create-job {:job-type    :send-email
                                :args        {:to "user@example.com"}
                                :priority    :high
                                :max-retries 3}
                               (random-uuid))]
  (ports/enqueue-job! job-queue :default new-job))

Priority levels: :critical, :high, :default, :low, :bulk.

Worker pool

(require '[boundary.jobs.shell.worker :as worker])

(def pool (worker/create-worker-pool
            {:queue-name :default :worker-count 5 :poll-interval-ms 500}
            queue store registry))

(worker/start-pool! pool)
(worker/stop-pool! pool)

Retry behaviour

Failed jobs retry with exponential backoff:

  • Attempt 1: immediate

  • Attempt 2: 30 seconds

  • Attempt 3: 5 minutes

  • Attempt 4: 1 hour

  • After max-retries: moved to dead letter queue

Redis counters

Stats are stored as Redis keys: stats:global:* and stats:queue:{name}:*.

Testing

clojure -M:test:db/h2 :jobs

Can you improve this documentation?Edit on GitHub

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