Job Queue v0.1.0 JobQueue.Worker behaviour
A behaviour and a module to handle some of the ceremony around a ConsumerSupervisor Worker.
Example
iex> # Setup Worker
...> defmodule JobQueueWorker do
...> use JobQueue.Worker
...>
...> def handle_event(event) do
...> {:ok, event}
...> end
...> end
...>
...> # Start Queue
...> {:ok, _queue} = JobQueue.Queue.start_link(WorkerQueue)
...>
...> # Setup Processor
...> {:ok, _processor} = JobQueue.Processor.start_link(WorkerQueue, JobQueueWorker)
...>
...> # Queue a Job
...> JobQueue.Queue.add_sync(WorkerQueue, :done)
{:ok, :done}
Compare this with the documentation of JobQueue.Processor to see the advantage to using Worker
Summary
Callbacks
A callback to handle events coming off the queue
Callbacks
Specs
handle_event(any) ::
{:ok, any} |
{:error, any} |
{:retry, any}
A callback to handle events coming off the queue.
Return Values
{:ok, message}- This willackthe message back to the Queue and reply withmessage{:error, message}- This willnackthe message back to the Queue withmessageas the error message.{:retry, message}- This will retry the job on the queue sending alongmessage.