Malla.Plugins.Base behaviour (malla v0.0.1-rc.1)

Copy Markdown View Source

The base plugin that all services include by default.

This module provides a set of essential callbacks that form the foundation of a Malla service's behavior. All services include this plugin in their dependency list, even if not explicitly declared.

Summary

Callbacks

Called from Malla.remote/4 and functions in Malla.Node when a remote callback is received. By default it will simply call apply(service_module, fun, args) but you can override it in your plugins to add tracing, etc.

Called when Malla.Service.drain/1 is called.

Called when the service status changes.

Types

class()

@type class() :: Malla.class()

config()

@type config() :: map()

cont()

@type cont() :: Malla.cont()

id()

@type id() :: Malla.id()

user_state()

@type user_state() :: map()

Callbacks

malla_authorize(term, term, authorize_opt)

(optional)
@callback malla_authorize(term(), term(), Malla.authorize_opt()) ::
  boolean() | {boolean(), term()} | {:error, term()}

Called when Malla.authorize/3 is called.

By default it returns {:error, :auth_not_implemented}

service_cb_in(atom, list, keyword)

(optional)
@callback service_cb_in(atom(), list(), keyword()) :: any()

Called from Malla.remote/4 and functions in Malla.Node when a remote callback is received. By default it will simply call apply(service_module, fun, args) but you can override it in your plugins to add tracing, etc.

service_drain()

(optional)
@callback service_drain() :: boolean() | cont()

Called when Malla.Service.drain/1 is called.

Each plugin must prepare for stop, cleaning its state.

If it could clean everything ok, it should return :cont to jump to next. If it could not, it should return false, meaning the drain could not complete, and it will be retried later.

service_is_ready?()

(optional)
@callback service_is_ready?() :: boolean() | cont()

Called when Malla.Service.is_ready?/1 is called.

Each plugin must return either 'false' (when it is not ready) or 'cont' to go to next (when it is ready).

service_status_changed(running_status)

(optional)
@callback service_status_changed(Malla.Service.running_status()) :: :ok

Called when the service status changes.

This callback is called when the running_status of the service changes. You should always return :cont so next plugin can receive the change too.

The service information can be obtained using Malla.get_service_id!/0 or by calling service_module.service() to get the full service struct.