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, and if there are attempts
132 remaining, transition back to "inactive" with a delay based on
133 "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.
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 # Check job state
163 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
164 my $state = $results->{jobs}[0]{state};
165
166 # Get job result
167 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
168 my $result = $results->{jobs}[0]{result};
169
170 These options are currently available:
171
172 ids
173 ids => ['23', '24']
174
175 List only jobs with these ids.
176
177 queues
178 queues => ['important', 'unimportant']
179
180 List only jobs in these queues.
181
182 states
183 states => ['inactive', 'active']
184
185 List only jobs in these states.
186
187 tasks
188 tasks => ['foo', 'bar']
189
190 List only jobs for these tasks.
191
192 These fields are currently available:
193
194 args
195 args => ['foo', 'bar']
196
197 Job arguments.
198
199 attempts
200 attempts => 25
201
202 Number of times performing this job will be attempted.
203
204 children
205 children => ['10026', '10027', '10028']
206
207 Jobs depending on this job.
208
209 created
210 created => 784111777
211
212 Epoch time job was created.
213
214 delayed
215 delayed => 784111777
216
217 Epoch time job was delayed to.
218
219 finished
220 finished => 784111777
221
222 Epoch time job was finished.
223
224 notes
225 notes => {foo => 'bar', baz => [1, 2, 3]}
226
227 Hash reference with arbitrary metadata for this job.
228
229 parents
230 parents => ['10023', '10024', '10025']
231
232 Jobs this job depends on.
233
234 priority
235 priority => 3
236
237 Job priority.
238
239 queue
240 queue => 'important'
241
242 Queue name.
243
244 result
245 result => 'All went well!'
246
247 Job result.
248
249 retried
250 retried => 784111777
251
252 Epoch time job has been retried.
253
254 retries
255 retries => 3
256
257 Number of times job has been retried.
258
259 started
260 started => 784111777
261
262 Epoch time job was started.
263
264 state
265 state => 'inactive'
266
267 Current job state, usually "active", "failed", "finished" or
268 "inactive".
269
270 task
271 task => 'foo'
272
273 Task name.
274
275 worker
276 worker => '154'
277
278 Id of worker that is processing the job.
279
280 list_locks
281 my $results = $backend->list_locks($offset, $limit);
282 my $results = $backend->list_locks($offset, $limit, {names => ['foo']});
283
284 Returns information about locks in batches.
285
286 # Check expiration time
287 my $results = $backend->list_locks(0, 1, {names => ['foo']});
288 my $expires = $results->{locks}[0]{expires};
289
290 These options are currently available:
291
292 names
293 names => ['foo', 'bar']
294
295 List only locks with these names.
296
297 These fields are currently available:
298
299 expires
300 expires => 784111777
301
302 Epoch time this lock will expire.
303
304 name
305 name => 'foo'
306
307 Lock name.
308
309 list_workers
310 my $results = $backend->list_workers($offset, $limit);
311 my $results = $backend->list_workers($offset, $limit, {ids => [23]});
312
313 Returns information about workers in batches.
314
315 # Check worker host
316 my $results = $backend->list_workers(0, 1, {ids => [$worker_id]});
317 my $host = $results->{workers}[0]{host};
318
319 These options are currently available:
320
321 ids
322 ids => ['23', '24']
323
324 List only workers with these ids.
325
326 These fields are currently available:
327
328 host
329 host => 'localhost'
330
331 Worker host.
332
333 jobs
334 jobs => ['10023', '10024', '10025', '10029']
335
336 Ids of jobs the worker is currently processing.
337
338 notified
339 notified => 784111777
340
341 Epoch time worker sent the last heartbeat.
342
343 pid
344 pid => 12345
345
346 Process id of worker.
347
348 started
349 started => 784111777
350
351 Epoch time worker was started.
352
353 status
354 status => {queues => ['default', 'important']}
355
356 Hash reference with whatever status information the worker would like
357 to share.
358
359 lock
360 my $bool = $backend->lock('foo', 3600);
361 my $bool = $backend->lock('foo', 3600, {limit => 20});
362
363 Try to acquire a named lock that will expire automatically after the
364 given amount of time in seconds. An expiration time of 0 can be used to
365 check if a named lock already exists without creating one.
366
367 These options are currently available:
368
369 limit
370 limit => 20
371
372 Number of shared locks with the same name that can be active at the
373 same time, defaults to 1.
374
375 new
376 my $backend = Minion::Backend::Pg->new('postgresql://postgres@/test');
377 my $backend = Minion::Backend::Pg->new(Mojo::Pg->new);
378
379 Construct a new Minion::Backend::Pg object.
380
381 note
382 my $bool = $backend->note($job_id, {mojo => 'rocks', minion => 'too'});
383
384 Change one or more metadata fields for a job.
385
386 receive
387 my $commands = $backend->receive($worker_id);
388
389 Receive remote control commands for worker.
390
391 register_worker
392 my $worker_id = $backend->register_worker;
393 my $worker_id = $backend->register_worker($worker_id);
394 my $worker_id = $backend->register_worker(
395 $worker_id, {status => {queues => ['default', 'important']}});
396
397 Register worker or send heartbeat to show that this worker is still
398 alive.
399
400 These options are currently available:
401
402 status
403 status => {queues => ['default', 'important']}
404
405 Hash reference with whatever status information the worker would like
406 to share.
407
408 remove_job
409 my $bool = $backend->remove_job($job_id);
410
411 Remove "failed", "finished" or "inactive" job from queue.
412
413 repair
414 $backend->repair;
415
416 Repair worker registry and job queue if necessary.
417
418 reset
419 $backend->reset;
420
421 Reset job queue.
422
423 retry_job
424 my $bool = $backend->retry_job($job_id, $retries);
425 my $bool = $backend->retry_job($job_id, $retries, {delay => 10});
426
427 Transition job back to "inactive" state, already "inactive" jobs may
428 also be retried to change options.
429
430 These options are currently available:
431
432 attempts
433 attempts => 25
434
435 Number of times performing this job will be attempted.
436
437 delay
438 delay => 10
439
440 Delay job for this many seconds (from now), defaults to 0.
441
442 parents
443 parents => [$id1, $id2, $id3]
444
445 Jobs this job depends on.
446
447 priority
448 priority => 5
449
450 Job priority.
451
452 queue
453 queue => 'important'
454
455 Queue to put job in.
456
457 stats
458 my $stats = $backend->stats;
459
460 Get statistics for the job queue.
461
462 These fields are currently available:
463
464 active_jobs
465 active_jobs => 100
466
467 Number of jobs in "active" state.
468
469 active_locks
470 active_locks => 100
471
472 Number of active named locks.
473
474 active_workers
475 active_workers => 100
476
477 Number of workers that are currently processing a job.
478
479 delayed_jobs
480 delayed_jobs => 100
481
482 Number of jobs in "inactive" state that are scheduled to run at
483 specific time in the future. Note that this field is EXPERIMENTAL and
484 might change without warning!
485
486 enqueued_jobs
487 enqueued_jobs => 100000
488
489 Rough estimate of how many jobs have ever been enqueued. Note that
490 this field is EXPERIMENTAL and might change without warning!
491
492 failed_jobs
493 failed_jobs => 100
494
495 Number of jobs in "failed" state.
496
497 finished_jobs
498 finished_jobs => 100
499
500 Number of jobs in "finished" state.
501
502 inactive_jobs
503 inactive_jobs => 100
504
505 Number of jobs in "inactive" state.
506
507 inactive_workers
508 inactive_workers => 100
509
510 Number of workers that are currently not processing a job.
511
512 uptime
513 uptime => 1000
514
515 Uptime in seconds.
516
517 unlock
518 my $bool = $backend->unlock('foo');
519
520 Release a named lock.
521
522 unregister_worker
523 $backend->unregister_worker($worker_id);
524
525 Unregister worker.
526
528 Minion, Mojolicious::Guides, <http://mojolicious.org>.
529
530
531
532perl v5.28.0 2018-04-19 Minion::Backend::Pg(3)