-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from diogob/metadata-channel
Add a configuration option to open a channel for metadata
- Loading branch information
Showing
14 changed files
with
186 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{-| | ||
Module : PostgresWebsockets.Context | ||
Description : Produce a context capable of running postgres-websockets sessions | ||
-} | ||
module PostgresWebsockets.Context | ||
( Context (..) | ||
, mkContext | ||
) where | ||
|
||
import Protolude | ||
import Data.Time.Clock (UTCTime, getCurrentTime) | ||
import Control.AutoUpdate ( defaultUpdateSettings | ||
, mkAutoUpdate | ||
, updateAction | ||
) | ||
import qualified Hasql.Pool as P | ||
|
||
import PostgresWebsockets.Config ( AppConfig(..) ) | ||
import PostgresWebsockets.HasqlBroadcast (newHasqlBroadcaster) | ||
import PostgresWebsockets.Broadcast (Multiplexer) | ||
|
||
data Context = Context { | ||
ctxConfig :: AppConfig | ||
, ctxPool :: P.Pool | ||
, ctxMulti :: Multiplexer | ||
, ctxGetTime :: IO UTCTime | ||
} | ||
|
||
-- | Given a configuration and a shutdown action (performed when the Multiplexer's listen connection dies) produces the context necessary to run sessions | ||
mkContext :: AppConfig -> IO () -> IO Context | ||
mkContext conf@AppConfig{..} shutdown = do | ||
Context conf | ||
<$> P.acquire (configPool, 10, pgSettings) | ||
<*> newHasqlBroadcaster shutdown (toS configListenChannel) configRetries pgSettings | ||
<*> mkGetTime | ||
where | ||
mkGetTime :: IO (IO UTCTime) | ||
mkGetTime = mkAutoUpdate defaultUpdateSettings {updateAction = getCurrentTime} | ||
pgSettings = toS configDatabase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.