Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
This module provides functionality for handling events.
Synopsis
- data Event result = MkEvent {
- name :: !Text
- serviceType :: !(ServiceType result)
- pollInterval :: !PollInterval
- raiseAlert :: result -> Maybe NaviNote
- repeatEvent :: !(RepeatEvent result)
- errorNote :: !ErrorNote
- data AnyEvent where
- MkAnyEvent :: (Eq result, Show result) => Event result -> AnyEvent
- runEvent :: (HasCallStack, MonadLoggerNamespace m, MonadSTM m, MonadSystemInfo m, Show result) => Event result -> m (EventSuccess result)
- data EventSuccess result = MkEventSuccess {
- result :: result
- repeatEvent :: RepeatEvent result
- raiseAlert :: result -> Maybe NaviNote
- data EventError = MkEventError {}
- data RepeatEvent a
- = NoRepeats !(IORef (Maybe a))
- | AllowRepeats
- data ErrorNote
- = NoErrNote
- | AllowErrNote !(RepeatEvent ())
- blockRepeat :: (Eq a, MonadLoggerNamespace m, MonadIORef m, Show a) => RepeatEvent a -> a -> m Bool
- blockErr :: (MonadLoggerNamespace m, MonadIORef m) => ErrorNote -> m Bool
- updatePrevTrigger :: (Eq a, MonadIORef m) => RepeatEvent a -> a -> m ()
Event type
Event
represents sending notifications. An event will:
- Query for information (i.e. run a shell command).
- Parse the result.
- Raise an alert if the result matches some condition.
MkEvent | |
|
Instances
(k ~ A_Lens, a ~ ErrorNote, b ~ ErrorNote) => LabelOptic "errorNote" k (Event result) (Event result) a b Source # | |
Defined in Navi.Event.Types | |
(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "name" k (Event result) (Event result) a b Source # | |
Defined in Navi.Event.Types | |
(k ~ A_Lens, a ~ PollInterval, b ~ PollInterval) => LabelOptic "pollInterval" k (Event result) (Event result) a b Source # | |
Defined in Navi.Event.Types | |
(k ~ A_Lens, a ~ (result -> Maybe NaviNote), b ~ (result -> Maybe NaviNote)) => LabelOptic "raiseAlert" k (Event result) (Event result) a b Source # | |
Defined in Navi.Event.Types | |
(k ~ A_Lens, a ~ RepeatEvent result, b ~ RepeatEvent result) => LabelOptic "repeatEvent" k (Event result) (Event result) a b Source # | |
Defined in Navi.Event.Types | |
(k ~ A_Lens, a ~ ServiceType result, b ~ ServiceType result) => LabelOptic "serviceType" k (Event result) (Event result) a b Source # | |
Defined in Navi.Event.Types | |
Show (Event result) Source # | |
Existentially quantifies result type on an Event
. Used so that we can
store different events in the same list.
MkAnyEvent :: (Eq result, Show result) => Event result -> AnyEvent |
runEvent :: (HasCallStack, MonadLoggerNamespace m, MonadSTM m, MonadSystemInfo m, Show result) => Event result -> m (EventSuccess result) Source #
Runs an event, i.e.,
- Queries the system via
MonadSystemInfo
. - Returns the parsed result.
Results
data EventSuccess result Source #
Holds the Event
data used after an event is successfully run.
Since: 0.1
MkEventSuccess | |
|
Instances
(k ~ A_Lens, a ~ (result -> Maybe NaviNote), b ~ (result -> Maybe NaviNote)) => LabelOptic "raiseAlert" k (EventSuccess result) (EventSuccess result) a b Source # | |
Defined in Navi.Event.Types labelOptic :: Optic k NoIx (EventSuccess result) (EventSuccess result) a b Source # | |
(k ~ A_Lens, a ~ RepeatEvent result, b ~ RepeatEvent result) => LabelOptic "repeatEvent" k (EventSuccess result) (EventSuccess result) a b Source # | |
Defined in Navi.Event.Types labelOptic :: Optic k NoIx (EventSuccess result) (EventSuccess result) a b Source # | |
(k ~ A_Lens, a ~ result, b ~ result) => LabelOptic "result" k (EventSuccess result) (EventSuccess result) a b Source # | |
Defined in Navi.Event.Types labelOptic :: Optic k NoIx (EventSuccess result) (EventSuccess result) a b Source # |
data EventError Source #
Represents an error when querying an Event
.
Instances
Exception EventError Source # | |
Defined in Navi.Event.Types | |
Show EventError Source # | |
Defined in Navi.Event.Types | |
Eq EventError Source # | |
Defined in Navi.Event.Types (==) :: EventError -> EventError -> Bool Source # (/=) :: EventError -> EventError -> Bool Source # | |
(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "long" k EventError EventError a b Source # | |
Defined in Navi.Event.Types labelOptic :: Optic k NoIx EventError EventError a b Source # | |
(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "name" k EventError EventError a b Source # | |
Defined in Navi.Event.Types labelOptic :: Optic k NoIx EventError EventError a b Source # | |
(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "short" k EventError EventError a b Source # | |
Defined in Navi.Event.Types labelOptic :: Optic k NoIx EventError EventError a b Source # |
Caching previous events/errors
data RepeatEvent a Source #
Determines if we are allowed to send off duplicate notifications
simultaneously. If we are not, then NoRepeats
holds the last trigger
so that we can detect duplicates.
NoRepeats !(IORef (Maybe a)) | |
AllowRepeats |
Instances
Show (RepeatEvent a) Source # | |
Defined in Navi.Event.Types |
Determines if we should send notifications for errors and, if so, if we allow repeats.
NoErrNote | |
AllowErrNote !(RepeatEvent ()) |
blockRepeat :: (Eq a, MonadLoggerNamespace m, MonadIORef m, Show a) => RepeatEvent a -> a -> m Bool Source #
Determines if we should block the event. The semantics are:
AllowRepeats
: never block (returnsFalse
).NoRepeats
: block only if the parametera
equals the previousa
stored in ourref
.
blockErr :: (MonadLoggerNamespace m, MonadIORef m) => ErrorNote -> m Bool Source #
Determines if we should block the error event. The semantics are:
NoErrNote
: always block (returnsTrue
).AllowErrNote
AllowRepeats
: never block (returnsFalse
).AllowErrNote
NoRepeats
: block only if we have sent a notifcation for this error before.
updatePrevTrigger :: (Eq a, MonadIORef m) => RepeatEvent a -> a -> m () Source #
If the reference is NoRepeats
then we overwrite the previous reference
with the new parameter. Otherwise we do nothing.