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.
45

METHODS

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

SEE ALSO

545       Minion, Mojolicious::Guides, <http://mojolicious.org>.
546
547
548
549perl v5.28.0                      2018-04-19                Minion::Backend(3)
Impressum