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