Skip to content
Hypha Stack

Spool

A durable job queue in your own Postgres, for OCaml 5 and Eio.

Source on GitHubLatest: 0.3.1

About

A job is a row written in the transaction that made the work owed, claimed by a runner under a lease, run outside every transaction, retried with backoff, and finished once however often it was attempted.

It runs over Rowtype's Postgres backend and names no driver. Runners in several processes claim from one queue without waiting on each other.

Messaging and jobs

Install

From Hypha's opam repository, on OCaml 5.5 or later:

opam repo add hypha https://github.com/hyphatech/opam-repository.git
opam install spool

Then in your dune file:

(libraries spool rowtype-postgres eio_main)

In code

  1. A kind: its name, its payload's Wiretype description and its queue. Enqueued in the caller's transaction.

    let receipt =
      Spool.Kind.make ~queue:"mail" ~timeout:Mtime.Span.min "receipt.send"
        order
    
    (* in the caller's transaction, through its own connection *)
    Spool.enqueue conn ~now ~unique:order_id receipt order_id
  2. A runner, with two workers on the mail queue.

    let runner =
      Spool.Runner.create ~sw ~net ~mono_clock ~now
        ~queues:[ ("mail", 2) ]
        [ Spool.handle receipt (fun _job order_id -> send_receipt order_id) ]
        conninfo
    in
    Spool.Runner.start runner

Ontology

  • EventQueuewaits in
  • QueueJobfeeds
  • ScheduleJobstarts
  • JobStatementruns

Build with Hypha.