agala v3.0.0 Agala
Link to this section Summary
Functions
Gets the value, stored under the given key
across bot’s supervisor lifetime.
Can be usefull to reveal some state across restarting handlers, responsers
and receivers
This method is used to show bot’s receive <-> handle load
TODO: Docs and examples
TODO: Docs and examples
Sets given value
under given key
across bot’s supervisor lifetime.
Can be usefull to store some state across restarting handlers, responsers
and receivers
Called when an application is started
Link to this section Functions
Gets the value, stored under the given key
across bot’s supervisor lifetime.
Can be usefull to reveal some state across restarting handlers, responsers
and receivers.
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
TODO: Docs and examples
TODO: Docs and examples
Sets given value
under given key
across bot’s supervisor lifetime.
Can be usefull to store some state across restarting handlers, responsers
and receivers.
Called when an application is started.
This function is called when an application is started using
Application.start/2
(and functions on top of that, such as
Application.ensure_started/2
). This function should start the top-level
process of the application (which should be the top supervisor of the
application’s supervision tree if the application follows the OTP design
principles around supervision).
start_type
defines how the application is started:
:normal
- used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another node and the application specification key:start_phases
is:undefined
.{:takeover, node}
- used if the application is distributed and is started on the current node because of a failover on the nodenode
.{:failover, node}
- used if the application is distributed and is started on the current node because of a failover on nodenode
, and the application specification key:start_phases
is not:undefined
.
start_args
are the arguments passed to the application in the :mod
specification key (e.g., mod: {MyApp, [:my_args]}
).
This function should either return {:ok, pid}
or {:ok, pid, state}
if
startup is successful. pid
should be the PID of the top supervisor. state
can be an arbitrary term, and if omitted will default to []
; if the
application is later stopped, state
is passed to the stop/1
callback (see
the documentation for the c:stop/1
callback for more information).
use Application
provides no default implementation for the start/2
callback.
Callback implementation for Application.start/2
.