agala v2.5.2 Agala.Bot.Storage behaviour
Behavior for modules that represent permanent storage system for Agala bot.
The problem
Sometimes, some bot parts can shut down because of internal errors. It has no sense to handle this errors in letitcrash approach. Thus, bot should have the place to store some data that should not be lost during restarts.
Of cource, developer should implement his own storage for business logic, but
providers
can use this storage to save internal data.
Implementation
Each Agala.Storage
should mandatory implement two methods: set/3
and get/2
.
This methods are used to keep and retrieve data.
If this storage is fundamental, it's lifecycle will be unlinked from Agala.Bot
instance. But, you can implement optional child_spec/1
method. In this case,
the Agala.Storage
module will be started inside Agala.Bot
supervision tree.
Link to this section Summary
Link to this section Callbacks
child_spec(bot_params)
(optional)
child_spec(bot_params :: Agala.BotParams.t()) :: :supervisor.child_spec()
child_spec(bot_params :: Agala.BotParams.t()) :: :supervisor.child_spec()
get(bot_params, key)
get(bot_params :: Agala.BotParams.t(), key :: Map.key()) :: Map.value()
get(bot_params :: Agala.BotParams.t(), key :: Map.key()) :: Map.value()
set(bot_params, key, value)
set(bot_params :: Agala.BotParams.t(), key :: Map.key(), value :: Map.value()) ::
{:ok, Map.value()}
set(bot_params :: Agala.BotParams.t(), key :: Map.key(), value :: Map.value()) :: {:ok, Map.value()}