v0.10.1

The defined worker is responsible for processing passed jobs, and
handling the job's success and failure callbacks. The defined
worker must export a perform/1 callback otherwise compilation
will fail.

Basic Worker

defmoduleMyApp.Workers.SignupMailerdouseQue.Workerdefperform(email)doMailer.send_email(to:email,message:"Thank you for signing up!")endend

You can also pattern match and use guard clauses like normal methods:

defmoduleMyApp.Workers.NotificationSenderdouseQue.Workerdefperform(type::like,to:user,count:count)doUser.notify(user,"You have #{count} new likes on your posts")enddefperform(type::message,to:user,from:sender)doUser.notify(user,"You received a new message from #{sender.name}")enddefperform(to:user)doUser.notify(user,"New activity on your profile")endend

Concurrency

By default, workers process one Job at a time. You can specify a custom
value by passing the concurrency option.

If you want all Jobs to be processed concurrently without any limit,
you can set the concurrency option to :infinity. The concurrency
option must either be a positive integer or :infinity, otherwise
it will raise an error during compilation.

Handle Job Success & Failure

The worker can also export optional on_success/1 and on_failure/2
callbacks that handle appropriate cases.

Setup and Teardown

You can similarly export optional on_setup/1 and on_teardown/1 callbacks
that are respectively run before and after the job is performed (successfully
or not). But instead of the job arguments, they pass the job struct as an
argument which holds a lot more internal details that can be useful for custom
features such as logging, metrics, requeuing and more.

This is a required callback that must be implemented by the worker.
If the worker doesn't export perform/1 method, compilation will
fail. It takes one argument which is whatever that's passed to
Que.add.

You can define it like any other method, use guard clauses and also
use pattern matching with multiple method definitions.