roger v1.0.0 Roger.Job behaviour
Base module for implementing Roger jobs.
To start, use Roger.Job
in your module. The only required callback
to implement is the perform/1
function.
defmodule TestJob do
use Roger.Job
def perform(_args) do
# perform some work here...
end
end
Other functions that can be implemented in a job module are the following:
queue_key/1
- Enforces job uniqueness. When returning a string
from this function, Roger enforces that only one job per queue key
can be put in the queue at the same time. Only when the job has left
the queue (after it has been executed), it will be possible to
enqueue a job with the same queue key again.
execution_key/1
- Enforces job execution serialization. When
returning a string from this function, Roger enforces that not more
than one job with the same job is executed concurrently. However, it
is still possible to have multiple jobs with the same execution key
enqueued, but jobs that have the same execution key will be put in a
waiting queue and processed serially.
queue_type/1
- Specifies which partition queue the job will run
on. By default, this function returns :default
, the default queue
type.
retryable?/0
- Specifies whether the job should be retried using
an exponential backoff scheme. The default implementation returns
false, meaning that jobs will not be retried.
Summary
Functions
Creates a new job based on a job module
Decode a binary payload into a Job struct, and validates it
Encodes a job into a binary payload
Enqueues a job in the given partition
Executes the given job
Constructs the AMQP options for publishing the job
Given a job, return its queue type
Given a job, return whether it’s retryable or not
Macros
To implement a job module, use Roger.Job
in your module, and
implement its required perform/1
function
Types
t :: %Roger.Job{args: term, execution_key: term, id: term, module: term, queue_key: term, queued_at: term, retry_count: term, started_at: term}
Functions
Creates a new job based on a job module.
The given module
must exist as an Elixir module and must be
implementing the Job behaviour (use Roger.Job
).
The function returns the Job struct, which can be sent off to the
queues using Job.enqueue/2
.
Decode a binary payload into a Job struct, and validates it.
Encodes a job into a binary payload.
Executes the given job.
This function is called from within a Job.Worker
process, there’s
no need to call it yourself.