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

Types

t()

Backbone is represented by it’s name as Atom

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

Link to this function bake_backbone_config()
bake_backbone_config() :: {:ok, t()} | {:ok, :empty} | no_return()

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.

Link to this function supervisor()
supervisor() :: [atom()] | []

Returns supervision config for specififed backbone.

If the backbone is not specified - returns empty list

Link to this section Callbacks

Link to this callback bake_backbone_config()
bake_backbone_config() :: :ok | no_return()

This function is given to configure the backbone.

Link to this callback get_config()
get_config() :: any()

This function is used to retrieve backbone’s config

Link to this callback get_load(bot_name)
get_load(bot_name :: atom()) :: {:ok, integer()} | {:error, any()}

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
Link to this callback init_bot(bot_name)
init_bot(bot_name :: atom()) :: :ok | {:error, any()}

This method is uused to initialize bot. It should be probably used upon bot initialization

Link to this callback pull(bot_name)
pull(bot_name :: Agala.Bot.name()) ::
  {:ok, any()} | {:error, :empty} | {:error, any()}

This method is used to pull available element from the queue, defined by Agala.Bot

Link to this callback push(bot_name, cid, value)
push(bot_name :: Agala.Bot.name(), cid :: any(), value :: any()) ::
  :ok | {:error, any()}

This method is used to add new element to the end of queue, defined by Agala.Bot and queue’s CID