1Minion::Backend(3)    User Contributed Perl Documentation   Minion::Backend(3)
2
3
4

NAME

6       Minion::Backend - Backend base class
7

SYNOPSIS

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

DESCRIPTION

34       Minion::Backend is an abstract base class for Minion backends, like
35       Minion::Backend::Pg.
36

ATTRIBUTES

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

METHODS

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

SEE ALSO

604       Minion, Mojolicious::Guides, <https://mojolicious.org>.
605
606
607
608perl v5.30.1                      2020-02-02                Minion::Backend(3)
Impressum