ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Queue.Buffer

Description

A bounded drop-newest hand-off in front of a MirrorQueue.

The serve path pays an STM write instead of the backend's producer call, which on SQS is an HTTP round trip. At the cap the newest job is dropped, which is safe because mirroring is demand-driven and the next demand re-enqueues it. The drain loop never returns: race it.

Synopsis

Buffered producer hand-off

newEnqueueBuffer Source #

Arguments

:: Int

Buffer depth: undelivered jobs the hand-off retains before it drops the newest.

-> (Int -> IO ())

Invoked on every drop with the running total. A drop is safe: the next demand re-enqueues.

-> (Int -> Text -> IO ())

Invoked on every backend delivery failure, with the running total and the detail.

-> MirrorQueue

The backend whose enqueue the buffer decouples from its callers.

-> IO (MirrorQueue, IO ()) 

Wrap a bounded drop-newest hand-off in front of a queue, so the serve path pays an STM write and not the backend producer call, an HTTP round trip on SQS. The drain loop never returns, race it.

Backend building blocks

writeOrDrop :: TBQueue MirrorJob -> TVar Int -> MirrorJob -> STM (Maybe Int) Source #

Hand a job to a bounded queue inside the caller's transaction. At the cap it drops the newest job and returns the running drop total, a safe loss because the next demand re-enqueues it.

reportWorthy :: Int -> Int -> Bool Source #

Whether the caller should report the n-th event in a rate-limited series: the first, then every interval-th.