ActiveJob
WIP
Installation
If available in Hex, the package can be installed
by adding activejob to your list of dependencies in mix.exs:
def deps do
[
{:activejob, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/activejob.
Preliminar API
With oban:
defmodule ActiveJob.ObanJob do
use ActiveJob.Base,
queue_adapter: ActiveJob.QueueAdapters.ObanAdapter
def perform(args) do
IO.inspect("THE GREAT OBAN JOB WAS PERFORMED!")
IO.inspect(args)
end
endExecute Job async
ObanJob.perform_later(%{a: "David", b: 2})Execute inline
ObanJob.perform_now(%{a: "David", b: 2})With inline, for testing:
defmodule ActiveJob.HelloJob do
use ActiveJob.Base,
queue_adapter: :inline,
def perform(greeter) do
IO.inspect("GREAT THE JOB HAS PERFORMED!")
end
endexecuting:
ObanJob.perform_later(%{a: "David", b: 2})Other options for enqueueing
use ActiveJob.Base,
queue_adapter: :inline,
queue_as: :aaa,
callbacks: %{
before: fn x -> IO.inspect("BEFORE") end,
after: fn x -> IO.inspect("AFTER") end
}Existing Queue libraries in Elixir
- rihanna - PostgreSQL storage, uses advisory locks
- exq - Redis backed, compatible with Sidekiq format - I like the “do you need exq?” section
- verk - Redis based as well, also supports sidekiq format
- que - backed by Mnesia which is a database builtin to erlang/otp so no extra infrastructure
- toniq - uses redis, hasn’t seen an update in over a year
- honeydew - pluggable storage, featuring in memory, Mnesia and ecto queues.
- ecto_job - backed by PostgreSQL, focussed on transactional behaviour, uses
pg_notifyso doesn’t do any database polling afaik (might be true for others here I just know this) - kiq - a rather new library, also redis backed and aiming at sidekiq compatibility, it was under heavy development around the jump of the year
- faktory_worker_ex - a worker for Mike Perham’s new more server based system faktory - woud especially be interested in opinions/experiences here.
- gen_queue - a generic interface to different queue systems mentioned above and others for flexibility