-
Notifications
You must be signed in to change notification settings - Fork 332
Drain rabbitmq consumers slowly from Cannon #4342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| Add rabbitmq consumers to the draining step on Cannon, in case of termination. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| module Cannon.Types | ||
| ( Env (..), | ||
| Cannon, | ||
| connectionLimit, | ||
| mapConcurrentlyCannon, | ||
| mkEnv, | ||
| runCannon, | ||
|
|
@@ -42,20 +43,25 @@ import Control.Monad.Catch | |
| import Data.Id | ||
| import Data.Text.Encoding | ||
| import Imports | ||
| import Network.AMQP qualified as Q | ||
| import Network.AMQP.Extended (AmqpEndpoint) | ||
| import Prometheus | ||
| import Servant qualified | ||
| import System.Logger qualified as Logger | ||
| import System.Logger.Class hiding (info) | ||
| import System.Random.MWC (GenIO) | ||
|
|
||
| connectionLimit :: Int | ||
| connectionLimit = 128 | ||
|
|
||
| ----------------------------------------------------------------------------- | ||
| -- Cannon monad | ||
|
|
||
| data Env = Env | ||
| { opts :: !Opts, | ||
| applog :: !Logger, | ||
| dict :: !(Dict Key Websocket), | ||
| websockets :: !(Dict Key Websocket), | ||
| rabbitConnections :: (Dict Key Q.Connection), | ||
| reqId :: !RequestId, | ||
| env :: !WS.Env | ||
| } | ||
|
|
@@ -95,20 +101,21 @@ mkEnv :: | |
| ClientState -> | ||
| Logger -> | ||
| Dict Key Websocket -> | ||
| Dict Key Q.Connection -> | ||
| Manager -> | ||
| GenIO -> | ||
| Clock -> | ||
| AmqpEndpoint -> | ||
| Env | ||
| mkEnv external o cs l d p g t rabbitmqOpts = | ||
| Env o l d (RequestId defRequestId) $ | ||
| WS.env external (o ^. cannon . port) (encodeUtf8 $ o ^. gundeck . host) (o ^. gundeck . port) l p d g t (o ^. drainOpts) rabbitmqOpts cs | ||
| mkEnv external o cs l d conns p g t rabbitmqOpts = | ||
| Env o l d conns (RequestId defRequestId) $ | ||
| WS.env external (o ^. cannon . port) (encodeUtf8 $ o ^. gundeck . host) (o ^. gundeck . port) l p d conns g t (o ^. drainOpts) rabbitmqOpts cs | ||
|
Comment on lines
+110
to
+112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's time to start using a record as a replacement to all these arguments to |
||
|
|
||
| runCannon :: Env -> Cannon a -> IO a | ||
| runCannon e c = runReaderT (unCannon c) e | ||
|
|
||
| clients :: Cannon (Dict Key Websocket) | ||
| clients = Cannon $ asks dict | ||
| clients = Cannon $ asks websockets | ||
|
|
||
| wsenv :: Cannon WS.Env | ||
| wsenv = Cannon $ do | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if Cannon crashes in between these two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it completely crashes, then there's no issue, it's not like the in-memory data will be preserved. Since this is bookkeeping for the graceful termination. If it starts graceful termination between these two steps, the worst case is trying to close a connection twice, which should be a no-op.