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

SEE ALSO

566       Minion, Mojolicious::Guides, <https://mojolicious.org>.
567
568
569
570perl v5.28.1                      2019-02-02                Minion::Backend(3)
Impressum