Safe Haskell | Safe-Infered |
---|
Implementation of configuration reader with watching support.
- type ConfigReader = IO (Result ConfigData)
- data ReloadModel
- = ReloadNotify
- | ReloadPoll Int
- data ServerState = ServerState {
- reloadModel :: ReloadModel
- reloadTime :: Integer
- reloadFStat :: FStat
- maxIdlePollRounds :: Int
- watchInterval :: Int
- pollInterval :: Int
- reloadRatelimit :: Integer
- initialPoll :: ReloadModel
- data ConfigReload
- moveToPolling :: String -> INotify -> FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO ReloadModel
- moveToNotify :: IO ReloadModel
- updateConfig :: FilePath -> (Result ConfigData -> IO ()) -> IO ()
- safeUpdateConfig :: FilePath -> FStat -> (Result ConfigData -> IO ()) -> IO (FStat, ConfigReload)
- onWatcherTimer :: FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO ()
- onWatcherInner :: FilePath -> (Result ConfigData -> IO ()) -> ServerState -> IO ServerState
- onPollTimer :: IO Bool -> FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO ()
- onPollInner :: IO Bool -> FilePath -> (Result ConfigData -> IO ()) -> ServerState -> IO (ServerState, Bool)
- addNotifier :: INotify -> FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO Bool
- onInotify :: INotify -> String -> (Result ConfigData -> IO ()) -> MVar ServerState -> Event -> IO ()
- initConfigReader :: (Result ConfigData -> IO ()) -> IO ()
Documentation
type ConfigReader = IO (Result ConfigData)Source
A type for functions that can return the configuration when executed.
data ServerState Source
ServerState | |
|
maxIdlePollRounds :: IntSource
watchInterval :: IntSource
pollInterval :: IntSource
reloadRatelimit :: IntegerSource
Configuration handling
Helper functions
moveToPolling :: String -> INotify -> FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO ReloadModelSource
Configuration loading
updateConfig :: FilePath -> (Result ConfigData -> IO ()) -> IO ()Source
safeUpdateConfig :: FilePath -> FStat -> (Result ConfigData -> IO ()) -> IO (FStat, ConfigReload)Source
Watcher threads
We have three threads/functions that can mutate the server state:
- the long-interval watcher (
onWatcherTimer
) - the polling watcher (
onPollTimer
) - the inotify event handler (
onInotify
)
All of these will mutate the server state under modifyMVar
or
modifyMVar_
, so that server transitions are more or less
atomic. The inotify handler remains active during polling mode, but
checks for polling mode and doesn't do anything in this case (this
check is needed even if we would unregister the event handler due
to how events are serialised).
onWatcherTimer :: FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO ()Source
onWatcherInner :: FilePath -> (Result ConfigData -> IO ()) -> ServerState -> IO ServerStateSource
onPollTimer :: IO Bool -> FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO ()Source
onPollInner :: IO Bool -> FilePath -> (Result ConfigData -> IO ()) -> ServerState -> IO (ServerState, Bool)Source
addNotifier :: INotify -> FilePath -> (Result ConfigData -> IO ()) -> MVar ServerState -> IO BoolSource
onInotify :: INotify -> String -> (Result ConfigData -> IO ()) -> MVar ServerState -> Event -> IO ()Source
initConfigReader :: (Result ConfigData -> IO ()) -> IO ()Source