Jumbo v1.0.1 Jumbo.Queue

Module that holds logic of single job processing queue.

It is supposed to be spawned as a process using start_link/2 or start/2 functions.

See Jumbo.QueueOptions for description of options that can be passed to such calls in order to customize queue’s behaviour.

Usage with OTP application

If you want to add it to your OTP app, you may do this as following:

defmodule SampleApp do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      # Queue for heavy tasks
      worker(Jumbo.Queue, [
        %Jumbo.QueueOptions{},
        [name: SampleApp.QueueHeavy]
      ], [id: :heavy]),

      # Queue for light tasks
      worker(Jumbo.Queue, [
        %Jumbo.QueueOptions{},
        [name: SampleApp.QueueLight]
      ], [id: :light]),
    ]

    opts = [strategy: :one_for_one, name: SampleApp]
    Supervisor.start_link(children, opts)
  end
end

However, please note that using Jumbo.QueueSupervisor may be a better idea.

Summary

Functions

Enqueues given job in the given queue

Retreives list of failed jobs from given queue

Retreives list of pending jobs from given queue

Retreives list of running jobs from given queue

Similar to start_link/2 but starts the queue outside of the supervision tree

Starts a job queue process and links it into current process

Functions

enqueue(server, job_module, job_args \\ [], timeout \\ 5000)
enqueue(pid, Jumbo.QueueState.job_module_t, Jumbo.QueueState.job_args_t, GenServer.timeout) :: :ok

Enqueues given job in the given queue.

Job is described as module and list of arguments that will be applied to the module’s perform function.

It always returns :ok.

Example

{:ok, queue} = Jumbo.Queue.start_link()

defmodule SampleJob do
  def perform(x) do
    IO.puts(x)
  end
end

Jumbo.Queue.enqueue(queue, SampleJob, ["hello world"])
get_failed_jobs(server, timeout \\ 5000)
get_failed_jobs(pid, GenServer.timeout) :: {:ok, [] | [Jumbo.RunningJob.t]}

Retreives list of failed jobs from given queue.

It returns {:ok, failed_jobs} where failed_jobs is a list of Jumbo.RunningJob structs.

Example

{:ok, queue} = Jumbo.Queue.start_link()

{:ok, failed_jobs} = Jumbo.Queue.failed_jobs(queue)
IO.puts inspect(failed_jobs)
get_pending_jobs(server, timeout \\ 5000)
get_pending_jobs(pid, GenServer.timeout) :: {:ok, [] | [Jumbo.RunningJob.t]}

Retreives list of pending jobs from given queue.

It returns {:ok, pending_jobs} where pending_jobs is a list of Jumbo.RunningJob structs.

Example

{:ok, queue} = Jumbo.Queue.start_link()

{:ok, pending_jobs} = Jumbo.Queue.pending_jobs(queue)
IO.puts inspect(pending_jobs)
get_running_jobs(server, timeout \\ 5000)
get_running_jobs(pid, GenServer.timeout) :: {:ok, [] | [Jumbo.RunningJob.t]}

Retreives list of running jobs from given queue.

It returns {:ok, running_jobs} where running_jobs is a list of Jumbo.RunningJob structs.

Example

{:ok, queue} = Jumbo.Queue.start_link()

{:ok, running_jobs} = Jumbo.Queue.running_jobs(queue)
IO.puts inspect(running_jobs)
start(queue_options \\ %Jumbo.QueueOptions{}, process_options \\ [])

Similar to start_link/2 but starts the queue outside of the supervision tree.

start_link(queue_options \\ %Jumbo.QueueOptions{}, process_options \\ [])

Starts a job queue process and links it into current process.

It accepts queue_options argument, which should contain Jumbo.QueueOptions struct.

It also accepts process_options argument, that works like GenServer’s options.

It returns the same return values as GenServer.start_link/3.