mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-28 04:05:17 +00:00
9d83a9c017
* configure message/file expiration time in INI file * correct comment Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
29 lines
822 B
Haskell
29 lines
822 B
Haskell
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
module Simplex.Messaging.Server.Expiration where
|
|
|
|
import Control.Monad.IO.Class
|
|
import Data.Int (Int64)
|
|
import Data.Time.Clock.System (SystemTime (..), getSystemTime)
|
|
|
|
data ExpirationConfig = ExpirationConfig
|
|
{ -- time after which the entity can be expired, seconds
|
|
ttl :: Int64,
|
|
-- interval to check expiration, seconds
|
|
checkInterval :: Int64
|
|
}
|
|
|
|
expireBeforeEpoch :: ExpirationConfig -> IO Int64
|
|
expireBeforeEpoch ExpirationConfig {ttl} = subtract ttl . systemSeconds <$> liftIO getSystemTime
|
|
|
|
showTTL :: Int64 -> String
|
|
showTTL s
|
|
| s' /= 0 = show s <> " seconds"
|
|
| ms' /= 0 = show ms <> " minutes"
|
|
| hs' /= 0 = show hs <> " hours"
|
|
| otherwise = show ds <> " days"
|
|
where
|
|
(ms, s') = s `divMod` 60
|
|
(hs, ms') = ms `divMod` 60
|
|
(ds, hs') = hs `divMod` 24
|