module Ecluse.Core.Queue.Lease (
Seconds (..),
MonoTime (..),
monotonicNow,
monoAfter,
monoSecondsBetween,
ReceiptLease (..),
receiptLease,
) where
import Ecluse.Core.Clock (MonoTime (MonoTime), monoAfter, monoSecondsBetween, monotonicNow)
newtype Seconds = Seconds Int
deriving stock (Seconds -> Seconds -> Bool
(Seconds -> Seconds -> Bool)
-> (Seconds -> Seconds -> Bool) -> Eq Seconds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Seconds -> Seconds -> Bool
== :: Seconds -> Seconds -> Bool
$c/= :: Seconds -> Seconds -> Bool
/= :: Seconds -> Seconds -> Bool
Eq, Eq Seconds
Eq Seconds =>
(Seconds -> Seconds -> Ordering)
-> (Seconds -> Seconds -> Bool)
-> (Seconds -> Seconds -> Bool)
-> (Seconds -> Seconds -> Bool)
-> (Seconds -> Seconds -> Bool)
-> (Seconds -> Seconds -> Seconds)
-> (Seconds -> Seconds -> Seconds)
-> Ord Seconds
Seconds -> Seconds -> Bool
Seconds -> Seconds -> Ordering
Seconds -> Seconds -> Seconds
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Seconds -> Seconds -> Ordering
compare :: Seconds -> Seconds -> Ordering
$c< :: Seconds -> Seconds -> Bool
< :: Seconds -> Seconds -> Bool
$c<= :: Seconds -> Seconds -> Bool
<= :: Seconds -> Seconds -> Bool
$c> :: Seconds -> Seconds -> Bool
> :: Seconds -> Seconds -> Bool
$c>= :: Seconds -> Seconds -> Bool
>= :: Seconds -> Seconds -> Bool
$cmax :: Seconds -> Seconds -> Seconds
max :: Seconds -> Seconds -> Seconds
$cmin :: Seconds -> Seconds -> Seconds
min :: Seconds -> Seconds -> Seconds
Ord, Int -> Seconds -> ShowS
[Seconds] -> ShowS
Seconds -> String
(Int -> Seconds -> ShowS)
-> (Seconds -> String) -> ([Seconds] -> ShowS) -> Show Seconds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Seconds -> ShowS
showsPrec :: Int -> Seconds -> ShowS
$cshow :: Seconds -> String
show :: Seconds -> String
$cshowList :: [Seconds] -> ShowS
showList :: [Seconds] -> ShowS
Show)
data ReceiptLease = ReceiptLease
{ ReceiptLease -> Seconds
rlWindow :: Seconds
, ReceiptLease -> MonoTime
rlExpiresAt :: MonoTime
, ReceiptLease -> MonoTime
rlCeilingAt :: MonoTime
}
deriving stock (ReceiptLease -> ReceiptLease -> Bool
(ReceiptLease -> ReceiptLease -> Bool)
-> (ReceiptLease -> ReceiptLease -> Bool) -> Eq ReceiptLease
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReceiptLease -> ReceiptLease -> Bool
== :: ReceiptLease -> ReceiptLease -> Bool
$c/= :: ReceiptLease -> ReceiptLease -> Bool
/= :: ReceiptLease -> ReceiptLease -> Bool
Eq, Int -> ReceiptLease -> ShowS
[ReceiptLease] -> ShowS
ReceiptLease -> String
(Int -> ReceiptLease -> ShowS)
-> (ReceiptLease -> String)
-> ([ReceiptLease] -> ShowS)
-> Show ReceiptLease
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReceiptLease -> ShowS
showsPrec :: Int -> ReceiptLease -> ShowS
$cshow :: ReceiptLease -> String
show :: ReceiptLease -> String
$cshowList :: [ReceiptLease] -> ShowS
showList :: [ReceiptLease] -> ShowS
Show)
receiptLease :: MonoTime -> Seconds -> Seconds -> ReceiptLease
receiptLease :: MonoTime -> Seconds -> Seconds -> ReceiptLease
receiptLease MonoTime
receivedAt Seconds
window Seconds
maxHold =
ReceiptLease
{ rlWindow :: Seconds
rlWindow = Seconds
window
, rlExpiresAt :: MonoTime
rlExpiresAt = MonoTime -> Double -> MonoTime
monoAfter MonoTime
receivedAt (Seconds -> Double
secondsOf Seconds
window)
, rlCeilingAt :: MonoTime
rlCeilingAt = MonoTime -> Double -> MonoTime
monoAfter MonoTime
receivedAt (Seconds -> Double
secondsOf Seconds
maxHold)
}
secondsOf :: Seconds -> Double
secondsOf :: Seconds -> Double
secondsOf (Seconds Int
seconds) = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
seconds