| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
- data LeasedReceipt
- leasedMessage :: LeasedReceipt -> QueueMessage
- withLeasedBatch :: (MonadUnliftIO m, KatipContext m) => LeaseOps -> [QueueMessage] -> ([LeasedReceipt] -> m a) -> m a
- whileLeased :: MonadUnliftIO m => LeasedReceipt -> m a -> m (Maybe a)
- disposing :: MonadUnliftIO m => LeasedReceipt -> m a -> m a
- data LeaseOps = LeaseOps {
- loRenew :: ReceiptHandle -> Seconds -> IO (Either TransportFault ())
- loNow :: IO MonoTime
- loWaitUntil :: MonoTime -> IO ()
- loRetryDelays :: [Int]
- queueLeaseOps :: MirrorQueue -> LeaseOps
- leaseRenewAt :: MonoTime -> MonoTime -> MonoTime
- leaseRetryUntil :: Seconds -> MonoTime -> MonoTime
- leaseRequest :: ReceiptLease -> MonoTime -> Maybe Seconds
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
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
| |
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.