ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Worker.Lease

Description

Holding every received receipt for as long as the worker needs it.

A backend hides a delivery for one window (Ecluse.Core.Queue.Lease). A batch runs sequentially, so a receipt waiting its turn and a receipt whose job runs long both outlive that window and would be redelivered to a second consumer. The controller renews each one from receipt until its disposition, and a renewal and a disposition never overlap on the same receipt. A receipt whose lease cannot be kept is dropped alone and left unacknowledged.

Synopsis

The controller

data LeasedReceipt Source #

One received receipt and the lease held over it. A renewal task runs per leased receipt, so a batch runs at most ten of them beside its single artifact task.

leasedMessage :: LeasedReceipt -> QueueMessage Source #

The message this receipt delivered.

withLeasedBatch :: (MonadUnliftIO m, KatipContext m) => LeaseOps -> [QueueMessage] -> ([LeasedReceipt] -> m a) -> m a Source #

Lease every receipt in a batch for the body's whole run, renewing each continually. Leaving the body cancels every renewal, so an unfinished receipt stays unacknowledged.

whileLeased :: MonadUnliftIO m => LeasedReceipt -> m a -> m (Maybe a) Source #

Run this receipt's work while its lease holds, cancelling the work the moment the lease is dropped. Nothing says the receipt was dropped, so nothing was decided for it.

disposing :: MonadUnliftIO m => LeasedReceipt -> m a -> m a Source #

Realise a receipt's disposition with its renewal stopped first, so none can follow an acknowledgement, a release for retry, or a terminal backoff.

The transport, clock, and pacing it runs on

data LeaseOps Source #

The transport, clock, and pacing a lease runs on, injected so a test drives renewal on a clock it controls rather than on real time.

Constructors

LeaseOps 

Fields

  • loRenew :: ReceiptHandle -> Seconds -> IO (Either TransportFault ())

    Reset one receipt's visibility window to the given duration.

  • loNow :: IO MonoTime

    The monotonic clock every lease deadline is measured on.

  • loWaitUntil :: MonoTime -> IO ()

    Wait until the given instant. It takes the instant, not a duration, so several waits running at once cannot each push a shared test clock on by their own full pause.

  • loRetryDelays :: [Int]

    The pacing between renewal attempts, in microseconds. Its length is the retry budget, and a retry stops early once the receipt's own margin runs out.

queueLeaseOps :: MirrorQueue -> LeaseOps Source #

The lease transport over a live queue handle, at the shipped clock and pacing.

Renewal arithmetic

leaseRenewAt :: MonoTime -> MonoTime -> MonoTime Source #

When a held lease is renewed: a third of the way into what is left of it, so two renewals can fail before the window lapses.

leaseRetryUntil :: Seconds -> MonoTime -> MonoTime Source #

The last instant a renewal may be sent: a tenth of the window before the deadline, the transport margin a request needs to land while the lease still holds.

leaseRequest :: ReceiptLease -> MonoTime -> Maybe Seconds Source #

The window a renewal asks for: the one the backend granted, clipped to what is left before its ceiling from receipt. Nothing once under a second is left, which drops the receipt.