queuetopia v1.2.0 Queuetopia behaviour View Source

Defines a queues machine.

A Queuetopia can manage multiple ordered blocking queues. All the queues share only the same scheduler and the poll interval. They are completely independant from each other.

A Queuetopia expects a performer to exist. For example, the performer can be implemented like this:

defmodule MyApp.MailQueue.Performer do
  @behaviour Queuetopia.Jobs.Performer

  @impl true
  def perform(%Queuetopia.Jobs.Job{action: "do_x"}) do
    do_x()
  end

  defp do_x(), do: {:ok, "done"}
end

And the Queuetopia:

defmodule MyApp.MailQueue do
  use Queuetopia,
    otp_app: :my_app,
    performer: MyApp.MailQueue.Performer,
    repo: MyApp.Repo
end

# config/config.exs
config :my_app, MyApp.MailQueue,
  poll_interval: 60 * 1_000,
  disable?: true

Link to this section Summary

Link to this section Callbacks

Link to this callback

create_job(binary, binary, map, list)

View Source

Specs

create_job(binary(), binary(), map(), [Job.option()]) ::
  {:error, Ecto.Changeset.t()} | {:ok, Job.t()}

Creates a job.

Job options

A job accepts the following options:

  • :timeout - The time in milliseconds to wait for the job to finish. (default: 60_000)
  • :max_backoff - default to 24 3600 1_000
  • :max_attempts - default to 20.

Examples

iex> MyApp.MailQueue.create_job("mails_queue_1", "send_mail", %{email_address: "toto@mail.com", body: "Welcome"}, [timeout: 1_000, max_backoff: 60_000])