sidetask v1.1.2 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 Tasks 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 at https://github.com/basho/sidejob.

Summary

Types

The sidejob resource

Functions

Creates a new sidejob resource that enforces the requested usage limit

Starts a task that can be awaited on as a child of the given sidejob_resource

Starts a task that can be awaited on as a child of the given sidejob_resource

Deletes an existing sidejob resource

Starts a task as a child of the given sidejob_resource

Starts a task as a child of the given sidejob_resource

Types

resource()
resource() :: atom

The sidejob resource

Functions

add_resource(name, limit)
add_resource(resource, non_neg_integer) :: :ok

Creates a new sidejob resource that enforces the requested usage limit.

See :sidejob.new_resource/4 for details.

async(sidejob_resource, fun)
async(resource, (... -> any)) ::
  {:ok, Task.t} |
  {:error, :overload}

Starts a task that can be awaited on as a child of the given sidejob_resource.

async(sidejob_resource, module, fun, args)
async(resource, module, atom, [term]) ::
  {:ok, Task.t} |
  {:error, :overload}

Starts a task that can be awaited on as a child of the given sidejob_resource.

delete_resource(name)
delete_resource(resource) ::
  :ok |
  {:error, :not_found | :running | :restarting}

Deletes an existing sidejob resource.

start_child(sidejob_resource, fun)
start_child(resource, (... -> any)) ::
  {:ok, pid} |
  {:error, :overload}

Starts a task as a 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.

start_child(sidejob_resource, module, fun, args)
start_child(resource, module, atom, [term]) ::
  {:ok, pid} |
  {:error, :overload}

Starts a task as a 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.