View Source AntikytheraCore.Alert.Handler behaviour (antikythera v0.5.1)
Behaviour module for alert handlers.
Implementations must be prefixed with AntikytheraCore.Alert.Handler
, e.g. AntikytheraCore.Alert.Handler.Email
.
This module also implements :gen_event
behaviour and installed as handlers for AntikytheraCore.Alert.Manager
processes.
Each installed handlers will call callbacks of their corresponding implementation modules (references to those modules are held in handler states).
A simple buffering/throttling mechanism is built in.
- Messages received by handlers will be sent out in "fast-then-delayed" pattern:
- Occasional messages will be flushed from the buffer and sent out in
fast_interval
. - Messages arriving too frequently will be buffered for
delayed_interval
until they are sent out.
- Occasional messages will be flushed from the buffer and sent out in
- By default,
fast_interval
is 60 seconds anddelayed_interval
is 1800 seconds.- They can be customized via core/gear configs. Specify fast_interval or delayed_interval for the handler.
Customization and installation of handlers
Through validate_config/1
callback, handler_config
will be validated
whether it includes sufficient information required for the implementation.
If the validation passed, a handler, with a reference to the implementation module, will be installed for that OTP application.
If the validation failed, the handler will not be installed, and will be uninstalled if it is installed already.
This means, customization and installation are purely done via core/gear config.
Summary
Callbacks
Send alert(s) for messages in the buffer, using handler_config
. Summarize messages if needed.
Must return messages which could not be sent for whatever reason for retry.
Oldest message comes first in messages
, same goes for returned messages.
Validate handler_config
whether it includes sufficient configurations for the handler.
Return true
when it is valid.
Callbacks
@callback send_alerts( messages :: [AntikytheraCore.Alert.Message.t()], handler_config :: AntikytheraCore.Alert.HandlerConfig.t(), otp_app_name :: :antikythera | Antikythera.GearName.t() ) :: [AntikytheraCore.Alert.Message.t()]
Send alert(s) for messages in the buffer, using handler_config
. Summarize messages if needed.
Must return messages which could not be sent for whatever reason for retry.
Oldest message comes first in messages
, same goes for returned messages.
Note: If the handler is trying to perform alerts which can take some time to finish (e.g. send email),
consider dispatching them to a temporary process.
In that case though, results of alerts cannot be received ([]
should always be returned).
@callback validate_config(handler_config :: AntikytheraCore.Alert.HandlerConfig.t()) :: boolean()
Validate handler_config
whether it includes sufficient configurations for the handler.
Return true
when it is valid.