Quantum v2.3.4 Quantum.JobBroadcaster View Source

This Module is here to broadcast added / removed tabs into the execution pipeline.

Link to this section Summary

Functions

Invoked to handle synchronous call/3 messages

Invoked to handle asynchronous cast/2 messages

Invoked on :producer stages

Invoked to handle all other messages

Start Job Broadcaster

Link to this section Types

Link to this type event() View Source
event() :: {:add, Quantum.Job.t()} | {:remove, Quantum.Job.t()}

Link to this section Functions

Link to this function handle_call(arg1, arg2, state) View Source

Invoked to handle synchronous call/3 messages.

call/3 will block until a reply is received (unless the call times out or nodes are disconnected).

request is the request message sent by a call/3, from is a two-element tuple containing the caller’s PID and a term that uniquely identifies the call, and state is the current state of the GenStage.

Returning {:reply, reply, [events], new_state} sends the response reply to the caller after events are dispatched (or buffered) and continues the loop with new state new_state. In case you want to deliver the reply before processing events, use reply/2 and return {:noreply, [event], state}.

Returning {:noreply, [event], new_state} does not send a response to the caller and processes the given events before continuing the loop with new state new_state. The response must be sent with reply/2.

Hibernating is also supported as an atom to be returned from either :reply and :noreply tuples.

Returning {:stop, reason, reply, new_state} stops the loop and terminate/2 is called with reason reason and state new_state. Then the reply is sent as the response to the call and the process exits with reason reason.

Returning {:stop, reason, new_state} is similar to {:stop, reason, reply, new_state} except that no reply is sent to the caller.

If this callback is not implemented, the default implementation by use GenStage will return {:stop, {:bad_call, request}, state}.

Callback implementation for GenStage.handle_call/3.

Link to this function handle_cast(arg1, state) View Source

Invoked to handle asynchronous cast/2 messages.

request is the request message sent by a cast/2 and state is the current state of the GenStage.

Returning {:noreply, [event], new_state} dispatches the events and continues the loop with new state new_state.

Returning {:noreply, [event], new_state, :hibernate} is similar to {:noreply, new_state} except the process is hibernated before continuing the loop. See the return values for GenServer.handle_call/3 for more information on hibernation.

Returning {:stop, reason, new_state} stops the loop and terminate/2 is called with the reason reason and state new_state. The process exits with reason reason.

If this callback is not implemented, the default implementation by use GenStage will return {:stop, {:bad_cast, request}, state}.

Callback implementation for GenStage.handle_cast/2.

Link to this function handle_demand(demand, state) View Source

Invoked on :producer stages.

This callback is invoked on :producer stages with the demand from consumers/dispatcher. The producer that implements this callback must either store the demand, or return the amount of requested events.

Must always be explicitly implemented by :producer stages.

Examples

def handle_demand(demand, state) do
  # We check if we're able to satisfy the demand and fetch
  # events if we aren't.
  events =
    if length(state.events) >= demand do
      state.events
    else
      # fetch_events()
    end

  # We dispatch only the requested number of events.
  {to_dispatch, remaining} = Enum.split(events, demand)

  {:noreply, to_dispatch, %{state | events: remaining}}
end

Callback implementation for GenStage.handle_demand/2.

Invoked to handle all other messages.

message is the message and state is the current state of the GenStage. When a timeout occurs the message is :timeout.

If this callback is not implemented, the default implementation by use GenStage will return {:noreply, [], state}.

Return values are the same as c:handle_cast/2.

Callback implementation for GenStage.handle_info/2.

Link to this function start_link(opts) View Source
start_link(Quantum.JobBroadcaster.StartOpts.t()) :: GenServer.on_start()

Start Job Broadcaster

Link to this function start_link(name, jobs, storage, scheduler, debug_logging) View Source
start_link(
  GenServer.server(),
  [Quantum.Job.t()],
  Quantum.Storage.Adapter,
  Quantum.Scheduler,
  boolean()
) :: GenServer.on_start()