View Source SuperWorker.Supervisor (SuperWorker v0.0.2)
Documentation for SuperWorker.Supervisor
.
This module is a new model for the Supervisor module.
Supervisor supports the following features:
- Group processes
- Chain processes
- Freedom processes
Group processes
Group processes are a set of processes that are started together. If one of the processes dies, all the processes in the group will be stopped.
Chain processes
Chain processes are a set of processes that are started one after another. The output of the previous process is passed to the next process.
Freedom processes
Freedom processes are independent processes that are started separately.
All type of processes can be started in parallel & can be stopped individually or in a group.
Examples
# Start a supervisor with 2 partitions & 2 groups: alias SuperWorker.Supervisor, as: Sup opts = [id: :sup1, number_of_partitions: 2, link: false] Sup.start(opts)
Sup.add_group(:sup1, [id: :group1, restart_strategy: :one_for_all]) Sup.add_group_worker(:sup1, :group1, {Dev, :task, [15]}, [id: :g1_1])
Sup.add_group(:sup1, [id: :group2, restart_strategy: :one_for_all]) Sup.add_group_worker(:sup1, :group2, fn ->
receice do
msg ->
:ok
end
end, [id: :g2_2])
Summary
Functions
Add a chain to the supervisor.
Chain's options follow docs in Chain
module.
Add a worker to the chain in supervisor.
Add a group to the supervisor.
Group's options follow docs in Group
module.
Add a worker to a group in the supervisor.
Function's options follow Worker
module.
Add a standalone worker process to the supervisor. function for start worker can be a function or a {module, function, arguments}. Standalone worker is run independently from other workers follow :one_to_one strategy. If worker crashes, it will check the restart strategy of worker then act accordingly.
Send data to all workers in a group.
Send data to all workers in current group of worker. Using for communite between workers in the same group.
get group structure from supervisor.
Check if supervisor is running. return true if supervisor is running, otherwise return false.
Send data to the entry worker in the chain. If chain doesn't has any worker, it will be dropped.
Send data to a worker in the group.
Send data to a random worker in the group.
Send data to other worker in the same group.
Send data directly to the worker (standalone, group, chain) in the supervisor.
Start supervisor for run standalone please set option :link to false. result format: {:ok, pid} or {:error, reason}
Stop supervisor. Type of shutdown
Functions
Add a chain to the supervisor.
Chain's options follow docs in Chain
module.
@spec add_chain_worker( atom(), atom(), {module(), atom(), list()} | fun(), list(), integer() ) :: {:ok, atom()} | {:error, any()}
Add a worker to the chain in supervisor.
Add a group to the supervisor.
Group's options follow docs in Group
module.
@spec add_group_worker( atom(), atom(), {module(), atom(), list()} | fun(), list(), integer() ) :: {:ok, atom()} | {:error, any()}
Add a worker to a group in the supervisor.
Function's options follow Worker
module.
@spec add_standalone_worker( atom(), {module(), atom(), list()} | fun(), list(), integer() ) :: {:ok, atom()} | {:error, any()}
Add a standalone worker process to the supervisor. function for start worker can be a function or a {module, function, arguments}. Standalone worker is run independently from other workers follow :one_to_one strategy. If worker crashes, it will check the restart strategy of worker then act accordingly.
Send data to all workers in a group.
Send data to all workers in current group of worker. Using for communite between workers in the same group.
get group structure from supervisor.
Check if supervisor is running. return true if supervisor is running, otherwise return false.
Send data to the entry worker in the chain. If chain doesn't has any worker, it will be dropped.
Send data to a worker in the group.
Send data to a random worker in the group.
Send data to other worker in the same group.
Send data directly to the worker (standalone, group, chain) in the supervisor.
Start supervisor for run standalone please set option :link to false. result format: {:ok, pid} or {:error, reason}
@spec stop(atom(), shutdown_type :: atom(), timeout :: integer()) :: {:ok, atom()} | {:error, any()}
Stop supervisor. Type of shutdown:
- :normal supervisor will send a message to worker for graceful shutdown. Not support for spawn process by function.
- :kill supervisor will kill worker.