BullMQ.QueueEvents.Handler behaviour (BullMQ v1.3.2)

View Source

Behaviour for queue event handlers.

Implement this behaviour to create structured event handlers.

Example

defmodule MyApp.QueueHandler do
  use BullMQ.QueueEvents.Handler

  @impl true
  def init(opts) do
    {:ok, %{count: 0}}
  end

  @impl true
  def handle_event(:completed, %{"jobId" => id}, state) do
    Logger.info("Job completed: #{id}")
    {:ok, %{state | count: state.count + 1}}
  end

  @impl true
  def handle_event(_event, _data, state) do
    {:ok, state}
  end
end

Summary

Callbacks

handle_event(event, data, state)

@callback handle_event(event :: atom(), data :: map(), state :: term()) ::
  {:ok, new_state :: term()} | {:error, reason :: term()}

init(opts)

@callback init(opts :: keyword()) :: {:ok, state :: term()} | {:error, reason :: term()}