Macaw.Data.Manager.Supervisor (macaw_data v0.21.1)

View Source

The source managers' supervisor (spec/01 §6.4.6, #461): everything a host's source managers run under. Moved from macaw_live's supervisor with the managers (dco-tek/macaw/macaw#478 decision 6a, #450), so a headless pipeline runs a named source's manager with no macaw_live.

The library starts no process of its own. A host adds one, names it, and passes the name wherever a manager is used (Macaw.Data.Manager.ensure/3, lookup/2, Macaw.Data.Manager.Reader.read/3):

children = [{Macaw.Data.Manager.Supervisor, name: MyApp.Managers}]

Its children, :one_for_one, each named from the name given (child/2):

  • <name>.Registry, a Registry of unique keys: each manager under {:manager, key} with its table. Its meta holds the options every manager reads: memory, detectors, notify, topic and told?. Nothing is held anywhere else, so two supervisors never share a manager, a budget or an option;
  • <name>.Managers, a DynamicSupervisor of the managers, :transient;
  • <name>.Tasks, a Task.Supervisor of the managers' turns (spec/01 §6.4.6);
  • <name>.Tables, the heir of every manager's table, which keeps it a grace past the manager's end, and the owner of the memory budget's table, <name>.Budget.

Summary

Types

What start_link/1 answers for options it can't use.

Functions

The name of one of the supervisor's children, derived from its name: :registry, :managers, :tasks, :tables, or :budget, the budget's table.

Its child spec, for a host's tree: a supervisor, its id the name given.

One of the options the supervisor name was started with, as every manager reads it: :memory, :detectors, :notify, :topic or :told?, its default when not given.

Starts the supervisor: {:ok, pid}, or {:error, faults} with every fault of its options at once, by key. Options

Types

fault()

@type fault() :: Macaw.Base.Fault.t()

What start_link/1 answers for options it can't use.

Functions

child(name, atom)

@spec child(atom(), :registry | :managers | :tasks | :tables | :budget) :: atom()

The name of one of the supervisor's children, derived from its name: :registry, :managers, :tasks, :tables, or :budget, the budget's table.

iex> Macaw.Data.Manager.Supervisor.child(MyApp.Managers, :registry)
MyApp.Managers.Registry
iex> Macaw.Data.Manager.Supervisor.child(MyApp.Managers, :managers)
MyApp.Managers.Managers
iex> Macaw.Data.Manager.Supervisor.child(MyApp.Managers, :tasks)
MyApp.Managers.Tasks
iex> Macaw.Data.Manager.Supervisor.child(MyApp.Managers, :tables)
MyApp.Managers.Tables
iex> Macaw.Data.Manager.Supervisor.child(MyApp.Managers, :budget)
MyApp.Managers.Budget

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Its child spec, for a host's tree: a supervisor, its id the name given.

option(name, key)

@spec option(atom(), :memory | :detectors | :notify | :topic | :told?) :: term()

One of the options the supervisor name was started with, as every manager reads it: :memory, :detectors, :notify, :topic or :told?, its default when not given.

start_link(opts)

@spec start_link(term()) :: {:ok, pid()} | {:error, [fault(), ...] | term()}

Starts the supervisor: {:ok, pid}, or {:error, faults} with every fault of its options at once, by key. Options:

  • name:, required, an atom: its registered name, every child's derived from it;
  • memory:, the bytes the managers may hold together (spec/01 §6.4.6), a positive integer, nil (no budget) by default;
  • detectors:, a source's name to its change detector (spec/01 §5): {module, opts} or {module, opts, every: ms} of a module implementing Macaw.Data.Source.Detector, %{} by default;
  • notify:, the change transport a manager subscribes through, {module, arg} of a loaded module exporting subscribe/2 (module.subscribe(arg, topic)), nil (none) by default; and topic:, a function of a source's name to its topic there, required with notify:. A manager subscribes, when it starts, to its source's topic, and a change notice is {:macaw_data, :changed, name, what} on it;
  • told?:, a function of a source's entry to whether its owner tells its manager when it has an answer (a derived output's), so a read it answered {:error, :loading} waits for that notice rather than drawing its readers down, and it is never polled; fn _ -> false end by default;
  • grace:, how long a manager's table outlives it, 60,000 ms by default.

Faults: {[:name], :required}, {[:name], {:type, :atom}}, {[key], :unknown_key}, {[:memory], {:type, :pos_integer}}, {[:detectors], {:type, :map}}, {[:detectors, name], {:type, Macaw.Data.Source.Detector}}, {[:notify], {:type, :notify}}, {[:topic], {:type, :function}} ({[:topic], :required} with a notify:), {[:told?], {:type, :function}} and {[:grace], {:type, :non_neg_integer}}. Options that aren't a keyword list are {[], {:type, :keyword}}.