1Minion::Backend::Pg(3)User Contributed Perl DocumentationMinion::Backend::Pg(3)
2
3
4
6 Minion::Backend::Pg - PostgreSQL backend
7
9 use Minion::Backend::Pg;
10
11 my $backend = Minion::Backend::Pg->new('postgresql://postgres@/test');
12
14 Minion::Backend::Pg is a backend for Minion based on Mojo::Pg. All
15 necessary tables will be created automatically with a set of migrations
16 named "minion". Note that this backend uses many bleeding edge
17 features, so only the latest, stable version of PostgreSQL is fully
18 supported.
19
21 Minion::Backend::Pg inherits all attributes from Minion::Backend and
22 implements the following new ones.
23
24 pg
25 my $pg = $backend->pg;
26 $backend = $backend->pg(Mojo::Pg->new);
27
28 Mojo::Pg object used to store all data.
29
31 Minion::Backend::Pg inherits all methods from Minion::Backend and
32 implements the following new ones.
33
34 broadcast
35 my $bool = $backend->broadcast('some_command');
36 my $bool = $backend->broadcast('some_command', [@args]);
37 my $bool = $backend->broadcast('some_command', [@args], [$id1, $id2, $id3]);
38
39 Broadcast remote control command to one or more workers.
40
41 dequeue
42 my $job_info = $backend->dequeue($worker_id, 0.5);
43 my $job_info = $backend->dequeue($worker_id, 0.5, {queues => ['important']});
44
45 Wait a given amount of time in seconds for a job, dequeue it and
46 transition from "inactive" to "active" state, or return "undef" if
47 queues were empty.
48
49 These options are currently available:
50
51 id
52 id => '10023'
53
54 Dequeue a specific job.
55
56 queues
57 queues => ['important']
58
59 One or more queues to dequeue jobs from, defaults to "default".
60
61 These fields are currently available:
62
63 args
64 args => ['foo', 'bar']
65
66 Job arguments.
67
68 id
69 id => '10023'
70
71 Job ID.
72
73 retries
74 retries => 3
75
76 Number of times job has been retried.
77
78 task
79 task => 'foo'
80
81 Task name.
82
83 enqueue
84 my $job_id = $backend->enqueue('foo');
85 my $job_id = $backend->enqueue(foo => [@args]);
86 my $job_id = $backend->enqueue(foo => [@args] => {priority => 1});
87
88 Enqueue a new job with "inactive" state.
89
90 These options are currently available:
91
92 attempts
93 attempts => 25
94
95 Number of times performing this job will be attempted, with a delay
96 based on "backoff" in Minion after the first attempt, defaults to 1.
97
98 delay
99 delay => 10
100
101 Delay job for this many seconds (from now), defaults to 0.
102
103 notes
104 notes => {foo => 'bar', baz => [1, 2, 3]}
105
106 Hash reference with arbitrary metadata for this job.
107
108 parents
109 parents => [$id1, $id2, $id3]
110
111 One or more existing jobs this job depends on, and that need to have
112 transitioned to the state "finished" before it can be processed.
113
114 priority
115 priority => 5
116
117 Job priority, defaults to 0. Jobs with a higher priority get
118 performed first.
119
120 queue
121 queue => 'important'
122
123 Queue to put job in, defaults to "default".
124
125 fail_job
126 my $bool = $backend->fail_job($job_id, $retries);
127 my $bool = $backend->fail_job($job_id, $retries, 'Something went wrong!');
128 my $bool = $backend->fail_job(
129 $job_id, $retries, {whatever => 'Something went wrong!'});
130
131 Transition from "active" to "failed" state with or without a result,
132 and if there are attempts remaining, transition back to "inactive" with
133 a delay based on "backoff" in Minion.
134
135 finish_job
136 my $bool = $backend->finish_job($job_id, $retries);
137 my $bool = $backend->finish_job($job_id, $retries, 'All went well!');
138 my $bool = $backend->finish_job(
139 $job_id, $retries, {whatever => 'All went well!'});
140
141 Transition from "active" to "finished" state with or without a result.
142
143 history
144 my $history = $backend->history;
145
146 Get history information for job queue. Note that this method is
147 EXPERIMENTAL and might change without warning!
148
149 These fields are currently available:
150
151 daily
152 daily => [{epoch => 12345, finished_jobs => 95, failed_jobs => 2}, ...]
153
154 Hourly counts for processed jobs from the past day.
155
156 list_jobs
157 my $results = $backend->list_jobs($offset, $limit);
158 my $results = $backend->list_jobs($offset, $limit, {states => ['inactive']});
159
160 Returns the information about jobs in batches.
161
162 # Get the total number of results (without limit)
163 my $num = $backend->list_jobs(0, 100, {queues => ['important']})->{total};
164
165 # Check job state
166 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
167 my $state = $results->{jobs}[0]{state};
168
169 # Get job result
170 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
171 my $result = $results->{jobs}[0]{result};
172
173 These options are currently available:
174
175 ids
176 ids => ['23', '24']
177
178 List only jobs with these ids.
179
180 queues
181 queues => ['important', 'unimportant']
182
183 List only jobs in these queues.
184
185 states
186 states => ['inactive', 'active']
187
188 List only jobs in these states.
189
190 tasks
191 tasks => ['foo', 'bar']
192
193 List only jobs for these tasks.
194
195 These fields are currently available:
196
197 args
198 args => ['foo', 'bar']
199
200 Job arguments.
201
202 attempts
203 attempts => 25
204
205 Number of times performing this job will be attempted.
206
207 children
208 children => ['10026', '10027', '10028']
209
210 Jobs depending on this job.
211
212 created
213 created => 784111777
214
215 Epoch time job was created.
216
217 delayed
218 delayed => 784111777
219
220 Epoch time job was delayed to.
221
222 finished
223 finished => 784111777
224
225 Epoch time job was finished.
226
227 id
228 id => 10025
229
230 Job id.
231
232 notes
233 notes => {foo => 'bar', baz => [1, 2, 3]}
234
235 Hash reference with arbitrary metadata for this job.
236
237 parents
238 parents => ['10023', '10024', '10025']
239
240 Jobs this job depends on.
241
242 priority
243 priority => 3
244
245 Job priority.
246
247 queue
248 queue => 'important'
249
250 Queue name.
251
252 result
253 result => 'All went well!'
254
255 Job result.
256
257 retried
258 retried => 784111777
259
260 Epoch time job has been retried.
261
262 retries
263 retries => 3
264
265 Number of times job has been retried.
266
267 started
268 started => 784111777
269
270 Epoch time job was started.
271
272 state
273 state => 'inactive'
274
275 Current job state, usually "active", "failed", "finished" or
276 "inactive".
277
278 task
279 task => 'foo'
280
281 Task name.
282
283 worker
284 worker => '154'
285
286 Id of worker that is processing the job.
287
288 list_locks
289 my $results = $backend->list_locks($offset, $limit);
290 my $results = $backend->list_locks($offset, $limit, {names => ['foo']});
291
292 Returns information about locks in batches.
293
294 # Get the total number of results (without limit)
295 my $num = $backend->list_locks(0, 100, {names => ['bar']})->{total};
296
297 # Check expiration time
298 my $results = $backend->list_locks(0, 1, {names => ['foo']});
299 my $expires = $results->{locks}[0]{expires};
300
301 These options are currently available:
302
303 names
304 names => ['foo', 'bar']
305
306 List only locks with these names.
307
308 These fields are currently available:
309
310 expires
311 expires => 784111777
312
313 Epoch time this lock will expire.
314
315 name
316 name => 'foo'
317
318 Lock name.
319
320 list_workers
321 my $results = $backend->list_workers($offset, $limit);
322 my $results = $backend->list_workers($offset, $limit, {ids => [23]});
323
324 Returns information about workers in batches.
325
326 # Get the total number of results (without limit)
327 my $num = $backend->list_workers(0, 100)->{total};
328
329 # Check worker host
330 my $results = $backend->list_workers(0, 1, {ids => [$worker_id]});
331 my $host = $results->{workers}[0]{host};
332
333 These options are currently available:
334
335 ids
336 ids => ['23', '24']
337
338 List only workers with these ids.
339
340 These fields are currently available:
341
342 id
343 id => 22
344
345 Worker id.
346
347 host
348 host => 'localhost'
349
350 Worker host.
351
352 jobs
353 jobs => ['10023', '10024', '10025', '10029']
354
355 Ids of jobs the worker is currently processing.
356
357 notified
358 notified => 784111777
359
360 Epoch time worker sent the last heartbeat.
361
362 pid
363 pid => 12345
364
365 Process id of worker.
366
367 started
368 started => 784111777
369
370 Epoch time worker was started.
371
372 status
373 status => {queues => ['default', 'important']}
374
375 Hash reference with whatever status information the worker would like
376 to share.
377
378 lock
379 my $bool = $backend->lock('foo', 3600);
380 my $bool = $backend->lock('foo', 3600, {limit => 20});
381
382 Try to acquire a named lock that will expire automatically after the
383 given amount of time in seconds. An expiration time of 0 can be used to
384 check if a named lock already exists without creating one.
385
386 These options are currently available:
387
388 limit
389 limit => 20
390
391 Number of shared locks with the same name that can be active at the
392 same time, defaults to 1.
393
394 new
395 my $backend = Minion::Backend::Pg->new('postgresql://postgres@/test');
396 my $backend = Minion::Backend::Pg->new(Mojo::Pg->new);
397
398 Construct a new Minion::Backend::Pg object.
399
400 note
401 my $bool = $backend->note($job_id, {mojo => 'rocks', minion => 'too'});
402
403 Change one or more metadata fields for a job.
404
405 receive
406 my $commands = $backend->receive($worker_id);
407
408 Receive remote control commands for worker.
409
410 register_worker
411 my $worker_id = $backend->register_worker;
412 my $worker_id = $backend->register_worker($worker_id);
413 my $worker_id = $backend->register_worker(
414 $worker_id, {status => {queues => ['default', 'important']}});
415
416 Register worker or send heartbeat to show that this worker is still
417 alive.
418
419 These options are currently available:
420
421 status
422 status => {queues => ['default', 'important']}
423
424 Hash reference with whatever status information the worker would like
425 to share.
426
427 remove_job
428 my $bool = $backend->remove_job($job_id);
429
430 Remove "failed", "finished" or "inactive" job from queue.
431
432 repair
433 $backend->repair;
434
435 Repair worker registry and job queue if necessary.
436
437 reset
438 $backend->reset;
439
440 Reset job queue.
441
442 retry_job
443 my $bool = $backend->retry_job($job_id, $retries);
444 my $bool = $backend->retry_job($job_id, $retries, {delay => 10});
445
446 Transition job back to "inactive" state, already "inactive" jobs may
447 also be retried to change options.
448
449 These options are currently available:
450
451 attempts
452 attempts => 25
453
454 Number of times performing this job will be attempted.
455
456 delay
457 delay => 10
458
459 Delay job for this many seconds (from now), defaults to 0.
460
461 parents
462 parents => [$id1, $id2, $id3]
463
464 Jobs this job depends on.
465
466 priority
467 priority => 5
468
469 Job priority.
470
471 queue
472 queue => 'important'
473
474 Queue to put job in.
475
476 stats
477 my $stats = $backend->stats;
478
479 Get statistics for the job queue.
480
481 These fields are currently available:
482
483 active_jobs
484 active_jobs => 100
485
486 Number of jobs in "active" state.
487
488 active_locks
489 active_locks => 100
490
491 Number of active named locks.
492
493 active_workers
494 active_workers => 100
495
496 Number of workers that are currently processing a job.
497
498 delayed_jobs
499 delayed_jobs => 100
500
501 Number of jobs in "inactive" state that are scheduled to run at
502 specific time in the future. Note that this field is EXPERIMENTAL and
503 might change without warning!
504
505 enqueued_jobs
506 enqueued_jobs => 100000
507
508 Rough estimate of how many jobs have ever been enqueued. Note that
509 this field is EXPERIMENTAL and might change without warning!
510
511 failed_jobs
512 failed_jobs => 100
513
514 Number of jobs in "failed" state.
515
516 finished_jobs
517 finished_jobs => 100
518
519 Number of jobs in "finished" state.
520
521 inactive_jobs
522 inactive_jobs => 100
523
524 Number of jobs in "inactive" state.
525
526 inactive_workers
527 inactive_workers => 100
528
529 Number of workers that are currently not processing a job.
530
531 uptime
532 uptime => 1000
533
534 Uptime in seconds.
535
536 unlock
537 my $bool = $backend->unlock('foo');
538
539 Release a named lock.
540
541 unregister_worker
542 $backend->unregister_worker($worker_id);
543
544 Unregister worker.
545
547 Minion, Mojolicious::Guides, <https://mojolicious.org>.
548
549
550
551perl v5.28.1 2019-02-02 Minion::Backend::Pg(3)