agala v3.0.0 Agala.Backbone behaviour
This behaviour specifies protocol, that should be implemented for each and every backbone,
that can be used with Agala
framework.
Link to this section Summary
Functions
This function will check backbone configuration
Returns supervision config for specififed backbone
Callbacks
This function is given to configure the backbone
This function is used to retrieve backbone’s config
This method is used to show bot’s receive <-> handle load
This method is uused to initialize bot. It should be probably used upon bot initialization
This method is used to pull available element from the queue, defined by Agala.Bot
This method is used to add new element to the end of queue, defined by Agala.Bot
and queue’s CID
Link to this section Types
Backbone is represented by it’s name as Atom
Link to this section Functions
This function will check backbone configuration.
If everything is right - ok tuple
with Agala.Backbone
implementation module will be returned.
If backbone is not specified -
If it’s not specified correct - function will rise.
Returns supervision config for specififed backbone.
If the backbone is not specified - returns empty list
Link to this section Callbacks
This function is given to configure the backbone.
This function is used to retrieve backbone’s config
This method is used to show bot’s receive <-> handle load.
- Active Receivers can use this information in order to stop retrieving new updates from third-parties.
- Passive Receivers can use this information to stop serving for a moment until load will not decrease.
Example:
# For active receivers
def get_updates() do
# check if service is overloaded
case Agala.Backbone.Foo.get_load(MyApp.MyBot) do
{:ok, overload} when overload > 1000 ->
# This server is overloaded
# waiting a bit, to let handlers deal with overload
:timer.sleep(10_000)
download_updates()
{:ok, normal} ->
# We should not wait - load is normal
download_updates()
end
end
# For passive receivers
def call(conn, opts) do
# check if service is overloaded
case Agala.Backbone.Foo.get_load(MyApp.MyBot) do
{:ok, overload} when overload > 1000 ->
# This server is overloaded
# Stop serving
send_500_http_error(conn)
{:ok, normal} ->
# We should not wait - load is normal
proceed_update(conn)
end
end
This method is uused to initialize bot. It should be probably used upon bot initialization
This method is used to pull available element from the queue, defined by Agala.Bot
This method is used to add new element to the end of queue, defined by Agala.Bot
and queue’s CID