Skip to content
Hypha Stack

Spool

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

Source on GitHubDocumentationLatest: 0.4.0

About

Fewer moving parts: jobs live in the database you already run, commit or roll back with your own changes, and are backed up with your data. Anything from a quick email to long-running work, scheduled, prioritised and retried with backoff.

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.