module Ecluse.Composition.MirrorRole (
spawnsWorker,
enqueuesJobs,
MirrorMintPlan (..),
mirrorMintPlan,
mirrorRoleRefusal,
) where
import Ecluse.Composition.BootError (BootError (MirrorRoleWithoutMirroring, SplitRoleNeedsDurableQueue))
import Ecluse.Composition.MirrorQueue (
MirrorQueuePlan (MemoryBackend, SqsBackend),
MirrorRuntimePlan (MirrorWith, NoMirroring),
)
import Ecluse.Composition.Types (MirrorRole (MirrorOnly, ServeAndMirror, ServeOnly), roleInvocation)
runsWorker :: MirrorRole -> Bool
runsWorker :: MirrorRole -> Bool
runsWorker = \case
MirrorRole
ServeAndMirror -> Bool
True
MirrorRole
ServeOnly -> Bool
False
MirrorRole
MirrorOnly -> Bool
True
spawnsWorker :: MirrorRole -> MirrorRuntimePlan -> Bool
spawnsWorker :: MirrorRole -> MirrorRuntimePlan -> Bool
spawnsWorker MirrorRole
role = \case
MirrorRuntimePlan
NoMirroring -> Bool
False
MirrorWith MirrorQueuePlan
_ -> MirrorRole -> Bool
runsWorker MirrorRole
role
enqueuesJobs :: MirrorRole -> Bool
enqueuesJobs :: MirrorRole -> Bool
enqueuesJobs = \case
MirrorRole
ServeAndMirror -> Bool
True
MirrorRole
ServeOnly -> Bool
True
MirrorRole
MirrorOnly -> Bool
False
data MirrorMintPlan
=
MintMirrorWrite
|
SkipMirrorWrite
deriving stock (MirrorMintPlan -> MirrorMintPlan -> Bool
(MirrorMintPlan -> MirrorMintPlan -> Bool)
-> (MirrorMintPlan -> MirrorMintPlan -> Bool) -> Eq MirrorMintPlan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MirrorMintPlan -> MirrorMintPlan -> Bool
== :: MirrorMintPlan -> MirrorMintPlan -> Bool
$c/= :: MirrorMintPlan -> MirrorMintPlan -> Bool
/= :: MirrorMintPlan -> MirrorMintPlan -> Bool
Eq, Int -> MirrorMintPlan -> ShowS
[MirrorMintPlan] -> ShowS
MirrorMintPlan -> String
(Int -> MirrorMintPlan -> ShowS)
-> (MirrorMintPlan -> String)
-> ([MirrorMintPlan] -> ShowS)
-> Show MirrorMintPlan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MirrorMintPlan -> ShowS
showsPrec :: Int -> MirrorMintPlan -> ShowS
$cshow :: MirrorMintPlan -> String
show :: MirrorMintPlan -> String
$cshowList :: [MirrorMintPlan] -> ShowS
showList :: [MirrorMintPlan] -> ShowS
Show)
mirrorMintPlan :: MirrorRole -> MirrorMintPlan
mirrorMintPlan :: MirrorRole -> MirrorMintPlan
mirrorMintPlan MirrorRole
role
| MirrorRole -> Bool
runsWorker MirrorRole
role = MirrorMintPlan
MintMirrorWrite
| Bool
otherwise = MirrorMintPlan
SkipMirrorWrite
mirrorRoleRefusal :: MirrorRole -> MirrorRuntimePlan -> Either [BootError] ()
mirrorRoleRefusal :: MirrorRole -> MirrorRuntimePlan -> Either [BootError] ()
mirrorRoleRefusal MirrorRole
role MirrorRuntimePlan
plan = case (MirrorRole
role, MirrorRuntimePlan
plan) of
(MirrorRole
ServeAndMirror, MirrorRuntimePlan
_) -> () -> Either [BootError] ()
forall a b. b -> Either a b
Right ()
(MirrorRole
ServeOnly, MirrorRuntimePlan
NoMirroring) -> () -> Either [BootError] ()
forall a b. b -> Either a b
Right ()
(MirrorRole
ServeOnly, MirrorWith SqsBackend{}) -> () -> Either [BootError] ()
forall a b. b -> Either a b
Right ()
(MirrorRole
ServeOnly, MirrorWith MirrorQueuePlan
MemoryBackend) -> [BootError] -> Either [BootError] ()
forall a b. a -> Either a b
Left [Text -> BootError
SplitRoleNeedsDurableQueue (MirrorRole -> Text
roleInvocation MirrorRole
role)]
(MirrorRole
MirrorOnly, MirrorWith SqsBackend{}) -> () -> Either [BootError] ()
forall a b. b -> Either a b
Right ()
(MirrorRole
MirrorOnly, MirrorWith MirrorQueuePlan
MemoryBackend) -> [BootError] -> Either [BootError] ()
forall a b. a -> Either a b
Left [Text -> BootError
SplitRoleNeedsDurableQueue (MirrorRole -> Text
roleInvocation MirrorRole
role)]
(MirrorRole
MirrorOnly, MirrorRuntimePlan
NoMirroring) -> [BootError] -> Either [BootError] ()
forall a b. a -> Either a b
Left [BootError
MirrorRoleWithoutMirroring]