Minion:...kend::Pg(3)
π Minion::Backend::Pg β PostgreSQL backend π
okay bestie, you found the page for Minion::Backend::Pg (that's the Minion:...kend::Pg(3) one, user-contributed Perl documentation, yes we're fancy). Buckle up, she's long, but she's worth it. π
β¨ SYNOPSIS β¨
use Minion::Backend::Pg;
my $backend = Minion::Backend::Pg->new('postgresql://postgres@/test');
πΈ DESCRIPTION πΈ
So Minion::Backend::Pg is a backend for Minion that's built on top of Mojo::Pg. The way that it just... handles the tables for you?? All the necessary tables get created automatically with a set of migrations named minion. No manual labor, we love a self-sufficient queen. π
But listen β this backend uses many bleeding edge features, so only the latest, stable version of PostgreSQL is fully supported. No cap. If you're running ancient Postgres, that's not her problem, that's a you problem. π
π ATTRIBUTES π
Minion::Backend::Pg inherits all attributes from Minion::Backend and implements the following new ones. Fresh ones only, we don't repeat ourselves. π
pg
my $pg = $backend->pg;
$backend = $backend->pg(Mojo::Pg->new);
The Mojo::Pg object used to store all the data. That's it, that's the whole attribute, she's the storage queen and she knows it. ποΈβ¨
π METHODS π
Minion::Backend::Pg inherits all methods from Minion::Backend and implements the following new ones.
broadcast
my $bool = $backend->broadcast('some_command');
my $bool = $backend->broadcast('some_command', [@args]);
my $bool = $backend->broadcast('some_command', [@args], [$id1, $id2, $id3]);
Broadcast a remote control command to one or more workers. Like a group chat but for workers, and you're the one sending. π’
dequeue
my $job_info = $backend->dequeue($worker_id, 0.5);
my $job_info = $backend->dequeue($worker_id, 0.5, {queues => ['important']});
Wait a given amount of time in seconds for a job, dequeue it, and transition it from inactive to active state. Or it returns undef if the queues were empty. π Ghosted by the queue.
These options are currently available:
idβ Dequeue one specific job.
id => '10023'
min_priorityβ Do not dequeue jobs with a lower priority.
min_priority => 3
queuesβ One or more queues to dequeue jobs from, defaults todefault.
queues => ['important']
tasksβ One or more tasks to dequeue jobs for, defaults to all tasks.
tasks => ['foo', 'bar']
These fields are currently available:
argsβ Job arguments.
args => ['foo', 'bar']
idβ Job ID.
id => '10023'
retriesβ Number of times the job has been retried.
retries => 3
taskβ Task name.
task => 'foo'
enqueue
my $job_id = $backend->enqueue('foo');
my $job_id = $backend->enqueue(foo => [@args]);
my $job_id = $backend->enqueue(foo => [@args] => {priority => 1});
Enqueue a new job with inactive state. Baby job, just born, not doing anything yet. πΌβ¨
These options are currently available:
attemptsβ Number of times performing this job will be attempted, with a delay based onbackoffin Minion after the first attempt, defaults to1.
attempts => 25
delayβ Delay the job for this many seconds (from now), defaults to0.
delay => 10
expireβ Job is valid for this many seconds (from now) before it expires.
expire => 300
laxβ Existing jobs this job depends on may also have transitioned to thefailedstate to allow for it to be processed, defaults tofalse.
lax => 1
notesβ Hash reference with arbitrary metadata for this job.
notes => {foo => 'bar', baz => [1, 2, 3]}
parentsβ One or more existing jobs this job depends on, and that need to have transitioned to the statefinishedbefore it can be processed.
parents => [$id1, $id2, $id3]
priorityβ Job priority, defaults to0. Jobs with a higher priority get performed first. Priorities can be positive or negative, but should be in the range between100and-100.
priority => 5
queueβ Queue to put the job in, defaults todefault.
queue => 'important'
fail_job
my $bool = $backend->fail_job($job_id, $retries);
my $bool = $backend->fail_job($job_id, $retries, 'Something went wrong!');
my $bool = $backend->fail_job(
$job_id, $retries, {whatever => 'Something went wrong!'});
Transition from active to failed state, with or without a result. And if there are attempts remaining, it transitions back to inactive with a delay based on backoff in Minion. She said "I'm not done with you yet." π€π
finish_job
my $bool = $backend->finish_job($job_id, $retries);
my $bool = $backend->finish_job($job_id, $retries, 'All went well!');
my $bool = $backend->finish_job(
$job_id, $retries, {whatever => 'All went well!'});
Transition from active to finished state, with or without a result. She ate and left no crumbs. πβ
history
my $history = $backend->history;
Get history information for the job queue. Receipts, basically. π§Ύ
These fields are currently available:
dailyβ Hourly counts for processed jobs from the past day.
daily => [{epoch => 12345, finished_jobs => 95, failed_jobs => 2}, ...]
list_jobs
my $results = $backend->list_jobs($offset, $limit);
my $results = $backend->list_jobs($offset, $limit, {states => ['inactive']});
Returns the information about jobs in batches.
# Get the total number of results (without limit)
my $num = $backend->list_jobs(0, 100, {queues => ['important']})->{total};
# Check job state
my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
my $state = $results->{jobs}[0]{state};
# Get job result
my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
my $result = $results->{jobs}[0]{result};
These options are currently available:
beforeβ List only jobs before this id.
before => 23
idsβ List only jobs with these ids.
ids => ['23', '24']
notesβ List only jobs with one of these notes.
notes => ['foo', 'bar']
queuesβ List only jobs in these queues.
queues => ['important', 'unimportant']
statesβ List only jobs in these states.
states => ['inactive', 'active']
tasksβ List only jobs for these tasks.
tasks => ['foo', 'bar']
These fields are currently available:
argsβ Job arguments.
args => ['foo', 'bar']
attemptsβ Number of times performing this job will be attempted.
attempts => 25
childrenβ Jobs depending on this job.
children => ['10026', '10027', '10028']
createdβ Epoch time the job was created.
created => 784111777
delayedβ Epoch time the job was delayed to.
delayed => 784111777
expiresβ Epoch time the job is valid until before it expires.
expires => 784111777
finishedβ Epoch time the job was finished.
finished => 784111777
idβ Job id.
id => 10025
laxβ Existing jobs this job depends on may also have failed to allow for it to be processed.
lax => 0
notesβ Hash reference with arbitrary metadata for this job.
notes => {foo => 'bar', baz => [1, 2, 3]}
parentsβ Jobs this job depends on.
parents => ['10023', '10024', '10025']
priorityβ Job priority.
priority => 3
queueβ Queue name.
queue => 'important'
resultβ Job result.
result => 'All went well!'
retriedβ Epoch time the job has been retried.
retried => 784111777
retriesβ Number of times the job has been retried.
retries => 3
startedβ Epoch time the job was started.
started => 784111777
stateβ Current job state, usuallyactive,failed,finishedorinactive.
state => 'inactive'
taskβ Task name.
task => 'foo'
timeβ Server time.
time => 78411177
workerβ Id of the worker that is processing the job.
worker => '154'
list_locks
my $results = $backend->list_locks($offset, $limit);
my $results = $backend->list_locks($offset, $limit, {names => ['foo']});
Returns information about locks in batches.
# Get the total number of results (without limit)
my $num = $backend->list_locks(0, 100, {names => ['bar']})->{total};
# Check expiration time
my $results = $backend->list_locks(0, 1, {names => ['foo']});
my $expires = $results->{locks}[0]{expires};
These options are currently available:
namesβ List only locks with these names.
names => ['foo', 'bar']
These fields are currently available:
expiresβ Epoch time this lock will expire.
expires => 784111777
idβ Lock id.
id => 1
nameβ Lock name.
name => 'foo'
list_workers
my $results = $backend->list_workers($offset, $limit);
my $results = $backend->list_workers($offset, $limit, {ids => [23]});
Returns information about workers in batches. It's giving employee directory. π
# Get the total number of results (without limit)
my $num = $backend->list_workers(0, 100)->{total};
# Check worker host
my $results = $backend->list_workers(0, 1, {ids => [$worker_id]});
my $host = $results->{workers}[0]{host};
These options are currently available:
beforeβ List only workers before this id.
before => 23
idsβ List only workers with these ids.
ids => ['23', '24']
These fields are currently available:
idβ Worker id.
id => 22
hostβ Worker host.
host => 'localhost'
jobsβ Ids of jobs the worker is currently processing.
jobs => ['10023', '10024', '10025', '10029']
notifiedβ Epoch time the worker sent the last heartbeat.
notified => 784111777
pidβ Process id of the worker.
pid => 12345
startedβ Epoch time the worker was started.
started => 784111777
statusβ Hash reference with whatever status information the worker would like to share.
status => {queues => ['default', 'important']}
lock
my $bool = $backend->lock('foo', 3600);
my $bool = $backend->lock('foo', 3600, {limit => 20});
Try to acquire a named lock that will expire automatically after the given amount of time in seconds. An expiration time of 0 can be used to check if a named lock already exists without creating one. π Just peeking, not touching.
These options are currently available:
limitβ Number of shared locks with the same name that can be active at the same time, defaults to1.
limit => 20
new
my $backend = Minion::Backend::Pg->new('postgresql://postgres@/test');
my $backend = Minion::Backend::Pg->new(Mojo::Pg->new);
Construct a new Minion::Backend::Pg object. Boom, she exists. π
note
my $bool = $backend->note($job_id, {mojo => 'rocks', minion => 'too'});
Change one or more metadata fields for a job. Setting a value to undef will remove the field. Setting it to undef is the polite way of saying "delete this, bestie." ποΈ
receive
my $commands = $backend->receive($worker_id);
Receive remote control commands for a worker. Inbox check time. π¬
register_worker
my $worker_id = $backend->register_worker;
my $worker_id = $backend->register_worker($worker_id);
my $worker_id = $backend->register_worker(
$worker_id, {status => {queues => ['default', 'important']}});
statusβ a hash ref with literally whatever status tea the worker wants to spill.
status => {queues => ['default', 'important']}
π remove_job π
my $bool = $backend->remove_job($job_id);
Yeets a failed, finished or inactive job out of the queue. Gone. Bye. π
π§ repair π§
$backend->repair;
Fixes up the worker registry and the job queue when they're looking a lil rough. It's giving "self-care but for your database" β¨
πΈ reset πΈ
$backend->reset({all => 1});
Resets the job queue. Nukes it. Fresh start energy.
These options are currently available:
allβ resets everything. The whole thing. Every last bit.
all => 1
locksβ resets only the locks, nothing else bestie.
locks => 1
π retry_job π
my $bool = $backend->retry_job($job_id, $retries);
my $bool = $backend->retry_job($job_id, $retries, {delay => 10});
Transitions a job back to the inactive state β and yes, jobs that are already inactive can also be retried, just to switch up their options. Main character redo arc π
These options are currently available:
attemptsβ how many times this job is gonna get attempted.
attempts => 25
delayβ delay the job by this many seconds (from now). Defaults to0.
delay => 10
expireβ the job stays valid for this many seconds (from now) before it expires.
expire => 300
laxβ existing jobs that this job depends on are allowed to have already transitioned to thefailedstate and it'll still get processed. Defaults tofalse.
lax => 1
parentsβ the jobs this job depends on.
parents => [$id1, $id2, $id3]
priorityβ the job's priority.
priority => 5
queueβ which queue to drop the job into.
queue => 'important'
π stats π
my $stats = $backend->stats;
Gets you the statistics for the job queue. The receipts, if you will. π§Ύ
These fields are currently available:
active_jobsβ how many jobs are in theactivestate.
active_jobs => 100
active_locksβ how many named locks are active.
active_locks => 100
active_workersβ how many workers are out here currently processing a job.
active_workers => 100
delayed_jobsβ how many jobs are in theinactivestate but scheduled to run at a specific time in the future.
delayed_jobs => 100
enqueued_jobsβ a rough estimate of how many jobs have ever been enqueued.
enqueued_jobs => 100000
failed_jobsβ how many jobs are in thefailedstate.
failed_jobs => 100
finished_jobsβ how many jobs are in thefinishedstate.
finished_jobs => 100
inactive_jobsβ how many jobs are in theinactivestate.
inactive_jobs => 100
inactive_workersβ how many workers are currently not processing a job. They're on break, they earned it β
inactive_workers => 100
uptimeβ uptime, in seconds.
uptime => 1000
workersβ how many workers are registered.
workers => 200;
π unlock π
my $bool = $backend->unlock('foo');
Releases a named lock. Freedom. π¦
πͺ unregister_worker πͺ
$backend->unregister_worker($worker_id);
Unregisters a worker. They're logging off, closing the tab, going to touch grass π±
β¨ SEE ALSO β¨
MinionMinion::Guide- <https://minion.pm>
Mojolicious::Guides- <https://mojolicious.org>
and that's a wrap on the whole page, bestie π this was perl v5.42.0, dated 2026-01-17, and it's giving Minion:...kend::Pg(3) β user contributed perl documentation, iconic as always. go forth and queue responsibly πβ¨
π¦ where this page comes from
- fedora 44: perl-Minion 11.0-2.fc44 Β· Artistic-2.0 AND CC-BY-SA-4.0 AND MIT AND ISC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms