-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce NotificationSubsystem (#3786)
This commit introduces the concept of Subsystems. Each of these subsystems will represent an important part of the domain concepts in the product that will interact with other subsystems. We will use effect systems to encode these subsystems and test them in isolation as much as possible. This commit consolidates all the code that spoke to gundeck from brig and galley into the NotificationSubsystem. https://wearezeta.atlassian.net/browse/WPB-5985 --------- Co-authored-by: Magnus Viernickel <magnus.viernickel@wire.com> Co-authored-by: Leif Battermann <leif.battermann@wire.com>
- Loading branch information
1 parent
2b104a0
commit 63d99ae
Showing
84 changed files
with
3,338 additions
and
1,760 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Start refactoring code into subsystems, first subsystem being the NotificationSubsystem. |
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,43 @@ | ||
module Data.Time.Clock.DiffTime | ||
( DiffTime, | ||
weeksToDiffTime, | ||
daysToDiffTime, | ||
hoursToDiffTime, | ||
minutesToDiffTime, | ||
secondsToDiffTime, | ||
millisecondsToDiffTime, | ||
microsecondsToDiffTime, | ||
nanosecondsToDiffTime, | ||
picosecondsToDiffTime, | ||
diffTimeToFullMicroseconds, | ||
diffTimeToPicoseconds, | ||
) | ||
where | ||
|
||
import Data.Time | ||
import Imports | ||
|
||
weeksToDiffTime, | ||
daysToDiffTime, | ||
hoursToDiffTime, | ||
minutesToDiffTime, | ||
millisecondsToDiffTime, | ||
microsecondsToDiffTime, | ||
nanosecondsToDiffTime :: | ||
Integer -> DiffTime | ||
weeksToDiffTime = daysToDiffTime . (7 *) | ||
daysToDiffTime = hoursToDiffTime . (24 *) | ||
hoursToDiffTime = minutesToDiffTime . (60 *) | ||
minutesToDiffTime = secondsToDiffTime . (60 *) | ||
millisecondsToDiffTime = picosecondsToDiffTime . (e9 *) | ||
microsecondsToDiffTime = picosecondsToDiffTime . (e6 *) | ||
nanosecondsToDiffTime = picosecondsToDiffTime . (e3 *) | ||
|
||
-- | Rounds down. Useful for 'threadDelay', 'timeout', etc. | ||
diffTimeToFullMicroseconds :: DiffTime -> Int | ||
diffTimeToFullMicroseconds = fromInteger . (`div` e6) . diffTimeToPicoseconds | ||
|
||
e3, e6, e9 :: Integer | ||
e3 = 1_000 | ||
e6 = 1_000_000 | ||
e9 = 1_000_000_000 |
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,32 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Wire.Sem.Delay where | ||
|
||
import Imports | ||
import Polysemy | ||
|
||
data Delay m a where | ||
Delay :: Int -> Delay m () | ||
|
||
makeSem ''Delay | ||
|
||
runDelay :: Member (Embed IO) r => Sem (Delay ': r) a -> Sem r a | ||
runDelay = interpret $ \case | ||
Delay i -> threadDelay i | ||
|
||
runControlledDelay :: forall r a. (Member (Embed IO) r) => MVar Int -> Sem (Delay : r) a -> Sem r a | ||
runControlledDelay tickSource = interpret $ \case | ||
Delay n -> waitForTicks n | ||
where | ||
waitForTicks :: Int -> Sem r () | ||
waitForTicks 0 = pure () | ||
waitForTicks remaining0 = do | ||
passedTicks <- takeMVar tickSource | ||
let remaining = remaining0 - passedTicks | ||
if remaining <= 0 | ||
then pure () | ||
else waitForTicks remaining | ||
|
||
runDelayInstantly :: Sem (Delay : r) a -> Sem r a | ||
runDelayInstantly = interpret $ \case | ||
Delay _ -> pure () |
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.