sidetask v1.0.0 SideTask
An alternative to Elixir’s Task.Supervisor
that uses Basho’s sidejob
library for better
parallelism and to support capacity limiting.
Elixir’s Task.Supervisor
is implemented as a single :simple_one_for_one
supervisor with the
individual Task
s as children. This means starting a new task has to go through this single
supervisor. Furthermore there is no limit to the number of workers that can be running at the same
time.
Basho’s sidejob
library spawns multiple supervisors (one for each scheduler by default) and
uses ETS tables to keep track of the number of workers, thereby making it possible to start
workers in parallel while also putting an upper bound on the number of running workers.
This module provides an API similar to Task.Supervisor
, with the addition that all calls that
start a new task require a sidejob resource as argument and can return {:error, :overload}
.
The add_resource/2
and delete_resource/1
functions are provided as convenience.
Name Registration A sidejob resource registers multiple local names. Read more about it in the sidejob docs.
Summary
Types
The sidejob resource
Functions
Create a new sidejob resource that enforces the requested usage limit
Starts a task that can be awaited on as child of the given sidejob_resource
Starts a task that can be awaited on as child of the given sidejob_resource
Deletes an existing sidejob resource
Starts a task as child of the given sidejob_resource
Starts a task as child of the given sidejob_resource
Types
resource :: atom
The sidejob resource
Functions
Specs
add_resource(resource, non_neg_integer) :: :ok
Create a new sidejob resource that enforces the requested usage limit.
See :sidejob.new_resource/4
for details.
Starts a task that can be awaited on as child of the given sidejob_resource
Starts a task that can be awaited on as child of the given sidejob_resource
Specs
delete_resource(resource) ::
:ok |
{:error, error} when error: :not_found | :running | :restarting
Deletes an existing sidejob resource.
Specs
start_child(resource, (... -> any)) ::
{:ok, pid} |
{:error, :overload}
Starts a task as child of the given sidejob_resource
.
Note that the spawned process is not linked to the caller, but only to the sidejob resource’s supervisor.
Specs
start_child(resource, module, atom, [term]) ::
{:ok, pid} |
{:error, :overload}
Starts a task as child of the given sidejob_resource
.
Note that the spawned process is not linked to the caller, but only to the sidejob resource’s supervisor.