Minion/Backend.pm

filter: Statementstmt 89.4% 34 / 38 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.5% 28 / 29 Podpod 100% 27 / 27 totaltotal 90.8% 89 / 98 CC 3 SCAR 7.2
CC
3
Cov
81%
auto_retry_job
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« Minion/Command/minion/worker.pm ↑ Summary Mojolicious/Plugin/Minion.pm »
1 package Minion::Backend;
2 1 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 has minion => undef, weak => 1;
7  
8 0 ▶sub auto_retry_job {
Subroutine auto_retry_job: not called CC=3 SCAR=24.8
Pod documented
9 0 my ($self, $id, $retries, $attempts) = @_;
10 0 ▶ return 1 if $attempts <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $attempts <= 1 0 0 0
11 0 my $delay = $self->minion->backoff->($retries);
12 0 ▶ return $self->retry_job($id, $retries, {attempts => $attempts > 1 ? $attempts - 1 : 1, delay => $delay});
Branch: 1 branch
BranchTrueFalseTotal
$attempts > 1 ? : 0 0 0
13 }
14  
15 1 ▶sub broadcast { croak 'Method "broadcast" not implemented by subclass' }
Subroutine broadcast: called CC=1 SCAR=0.0
Pod documented
16 1 ▶sub dequeue { croak 'Method "dequeue" not implemented by subclass' }
Subroutine dequeue: called CC=1 SCAR=0.0
Pod documented
17 1 ▶sub dispatch_schedules { croak 'Method "dispatch_schedules" not implemented by subclass' }
Subroutine dispatch_schedules: called CC=1 SCAR=0.0
Pod documented
18 1 ▶sub enqueue { croak 'Method "enqueue" not implemented by subclass' }
Subroutine enqueue: called CC=1 SCAR=0.0
Pod documented
19 1 ▶sub fail_job { croak 'Method "fail_job" not implemented by subclass' }
Subroutine fail_job: called CC=1 SCAR=0.0
Pod documented
20 1 ▶sub finish_job { croak 'Method "finish_job" not implemented by subclass' }
Subroutine finish_job: called CC=1 SCAR=0.0
Pod documented
21 1 ▶sub history { croak 'Method "history" not implemented by subclass' }
Subroutine history: called CC=1 SCAR=0.0
Pod documented
22 1 ▶sub list_jobs { croak 'Method "list_jobs" not implemented by subclass' }
Subroutine list_jobs: called CC=1 SCAR=0.0
Pod documented
23 1 ▶sub list_locks { croak 'Method "list_locks" not implemented by subclass' }
Subroutine list_locks: called CC=1 SCAR=0.0
Pod documented
24 1 ▶sub list_schedules { croak 'Method "list_schedules" not implemented by subclass' }
Subroutine list_schedules: called CC=1 SCAR=0.0
Pod documented
25 1 ▶sub list_workers { croak 'Method "list_workers" not implemented by subclass' }
Subroutine list_workers: called CC=1 SCAR=0.0
Pod documented
26 1 ▶sub lock { croak 'Method "lock" not implemented by subclass' }
Subroutine lock: called CC=1 SCAR=0.0
Pod documented
27 1 ▶sub note { croak 'Method "note" not implemented by subclass' }
Subroutine note: called CC=1 SCAR=0.0
Pod documented
28 1 ▶sub pause_schedule { croak 'Method "pause_schedule" not implemented by subclass' }
Subroutine pause_schedule: called CC=1 SCAR=0.0
Pod documented
29 1 ▶sub receive { croak 'Method "receive" not implemented by subclass' }
Subroutine receive: called CC=1 SCAR=0.0
Pod documented
30 1 ▶sub register_worker { croak 'Method "register_worker" not implemented by subclass' }
Subroutine register_worker: called CC=1 SCAR=0.0
Pod documented
31 1 ▶sub remove_job { croak 'Method "remove_job" not implemented by subclass' }
Subroutine remove_job: called CC=1 SCAR=0.0
Pod documented
32 1 ▶sub repair { croak 'Method "repair" not implemented by subclass' }
Subroutine repair: called CC=1 SCAR=0.0
Pod documented
33 1 ▶sub reset { croak 'Method "reset" not implemented by subclass' }
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
34 1 ▶sub resume_schedule { croak 'Method "resume_schedule" not implemented by subclass' }
Subroutine resume_schedule: called CC=1 SCAR=0.0
Pod documented
35 1 ▶sub retry_job { croak 'Method "retry_job" not implemented by subclass' }
Subroutine retry_job: called CC=1 SCAR=0.0
Pod documented
36 1 ▶sub schedule { croak 'Method "schedule" not implemented by subclass' }
Subroutine schedule: called CC=1 SCAR=0.0
Pod documented
37 1 ▶sub stats { croak 'Method "stats" not implemented by subclass' }
Subroutine stats: called CC=1 SCAR=0.0
Pod documented
38 1 ▶sub unlock { croak 'Method "unlock" not implemented by subclass' }
Subroutine unlock: called CC=1 SCAR=0.0
Pod documented
39 1 ▶sub unregister_worker { croak 'Method "unregister_worker" not implemented by subclass' }
Subroutine unregister_worker: called CC=1 SCAR=0.0
Pod documented
40 1 ▶sub unschedule { croak 'Method "unschedule" not implemented by subclass' }
Subroutine unschedule: called CC=1 SCAR=0.0
Pod documented
41  
42 1 1;
43  
44 =encoding utf8
45  
46 =head1 NAME
47  
48 Minion::Backend - Backend base class
49  
50 =head1 SYNOPSIS
51  
52 package Minion::Backend::MyBackend;
53 use Mojo::Base 'Minion::Backend';
54  
55 sub broadcast {...}
56 sub dequeue {...}
57 sub dispatch_schedules {...}
58 sub enqueue {...}
59 sub fail_job {...}
60 sub finish_job {...}
61 sub history {...}
62 sub list_jobs {...}
63 sub list_locks {...}
64 sub list_schedules {...}
65 sub list_workers {...}
66 sub lock {...}
67 sub note {...}
68 sub pause_schedule {...}
69 sub receive {...}
70 sub register_worker {...}
71 sub remove_job {...}
72 sub repair {...}
73 sub reset {...}
74 sub resume_schedule {...}
75 sub retry_job {...}
76 sub schedule {...}
77 sub stats {...}
78 sub unlock {...}
79 sub unregister_worker {...}
80 sub unschedule {...}
81  
82 =head1 DESCRIPTION
83  
84 L<Minion::Backend> is an abstract base class for L<Minion> backends, like L<Minion::Backend::Pg>.
85  
86 =head1 ATTRIBUTES
87  
88 L<Minion::Backend> implements the following attributes.
89  
90 =head2 minion
91  
92 my $minion = $backend->minion;
93 $backend = $backend->minion(Minion->new);
94  
95 L<Minion> object this backend belongs to. Note that this attribute is weakened.
96  
97 =head1 METHODS
98  
99 L<Minion::Backend> inherits all methods from L<Mojo::Base> and implements the following new ones.
100  
101 =head2 auto_retry_job
102  
103 my $bool = $backend->auto_retry_job($job_id, $retries, $attempts);
104  
105 Automatically L</"retry"> job with L<Minion/"backoff"> if there are attempts left, used to implement backends like
106 L<Minion::Backend::Pg>.
107  
108 =head2 broadcast
109  
110 my $bool = $backend->broadcast('some_command');
111 my $bool = $backend->broadcast('some_command', [@args]);
112 my $bool = $backend->broadcast('some_command', [@args], [$id1, $id2, $id3]);
113  
114 Broadcast remote control command to one or more workers. Meant to be overloaded in a subclass.
115  
116 =head2 dequeue
117  
118 my $job_info = $backend->dequeue($worker_id, 0.5);
119 my $job_info = $backend->dequeue($worker_id, 0.5, {queues => ['important']});
120  
121 Wait a given amount of time in seconds for a job, dequeue it and transition from C<inactive> to C<active> state, or
122 return C<undef> if queues were empty. Meant to be overloaded in a subclass.
123  
124 These options are currently available:
125  
126 =over 2
127  
128 =item id
129  
130 id => '10023'
131  
132 Dequeue a specific job.
133  
134 =item min_priority
135  
136 min_priority => 3
137  
138 Do not dequeue jobs with a lower priority.
139  
140 =item queues
141  
142 queues => ['important']
143  
144 One or more queues to dequeue jobs from, defaults to C<default>.
145  
146 =item tasks
147  
148 tasks => ['foo', 'bar']
149  
150 One or more tasks to dequeue jobs for, defaults to all.
151  
152 =back
153  
154 These fields are currently available:
155  
156 =over 2
157  
158 =item args
159  
160 args => ['foo', 'bar']
161  
162 Job arguments.
163  
164 =item id
165  
166 id => '10023'
167  
168 Job ID.
169  
170 =item retries
171  
172 retries => 3
173  
174 Number of times job has been retried.
175  
176 =item task
177  
178 task => 'foo'
179  
180 Task name.
181  
182 =back
183  
184 =head2 dispatch_schedules
185  
186 my $dispatched = $backend->dispatch_schedules;
187  
188 Enqueue jobs for all schedules whose firing time has been reached, advance their firing times to the next match, and
189 return information about each dispatch as an array reference. Coordinates across multiple workers so a single dispatch
190 cycle never enqueues a schedule twice. Meant to be overloaded in a subclass.
191  
192 Each dispatched entry contains these fields:
193  
194 =over 2
195  
196 =item id
197  
198 id => 23
199  
200 Schedule id.
201  
202 =item job
203  
204 job => '10025'
205  
206 Id of the job that was just enqueued.
207  
208 =item name
209  
210 name => 'daily'
211  
212 Schedule name.
213  
214 =back
215  
216 =head2 enqueue
217  
218 my $job_id = $backend->enqueue('foo');
219 my $job_id = $backend->enqueue(foo => [@args]);
220 my $job_id = $backend->enqueue(foo => [@args] => {priority => 1});
221  
222 Enqueue a new job with C<inactive> state. Meant to be overloaded in a subclass.
223  
224 These options are currently available:
225  
226 =over 2
227  
228 =item attempts
229  
230 attempts => 25
231  
232 Number of times performing this job will be attempted, with a delay based on L<Minion/"backoff"> after the first
233 attempt, defaults to C<1>.
234  
235 =item delay
236  
237 delay => 10
238  
239 Delay job for this many seconds (from now), defaults to C<0>.
240  
241 =item expire
242  
243 expire => 300
244  
245 Job is valid for this many seconds (from now) before it expires.
246  
247 =item lax
248  
249 lax => 1
250  
251 Existing jobs this job depends on may also have transitioned to the C<failed> state to allow for it to be processed,
252 defaults to C<false>.
253  
254 =item notes
255  
256 notes => {foo => 'bar', baz => [1, 2, 3]}
257  
258 Hash reference with arbitrary metadata for this job.
259  
260 =item parents
261  
262 parents => [$id1, $id2, $id3]
263  
264 One or more existing jobs this job depends on, and that need to have transitioned to the state C<finished> before it
265 can be processed.
266  
267 =item priority
268  
269 priority => 5
270  
271 Job priority, defaults to C<0>. Jobs with a higher priority get performed first. Priorities can be positive or negative,
272 but should be in the range between C<100> and C<-100>.
273  
274 =item queue
275  
276 queue => 'important'
277  
278 Queue to put job in, defaults to C<default>.
279  
280 =back
281  
282 =head2 fail_job
283  
284 my $bool = $backend->fail_job($job_id, $retries);
285 my $bool = $backend->fail_job($job_id, $retries, 'Something went wrong!');
286 my $bool = $backend->fail_job(
287 $job_id, $retries, {whatever => 'Something went wrong!'});
288  
289 Transition from C<active> to C<failed> state with or without a result, and if there are attempts remaining, transition
290 back to C<inactive> with a delay based on L<Minion/"backoff">. Meant to be overloaded in a subclass.
291  
292 =head2 finish_job
293  
294 my $bool = $backend->finish_job($job_id, $retries);
295 my $bool = $backend->finish_job($job_id, $retries, 'All went well!');
296 my $bool = $backend->finish_job(
297 $job_id, $retries, {whatever => 'All went well!'});
298  
299 Transition from C<active> to C<finished> state with or without a result. Meant to be overloaded in a subclass.
300  
301 =head2 history
302  
303 my $history = $backend->history;
304  
305 Get history information for job queue. Meant to be overloaded in a subclass.
306  
307 These fields are currently available:
308  
309 =over 2
310  
311 =item daily
312  
313 daily => [{epoch => 12345, finished_jobs => 95, failed_jobs => 2}, ...]
314  
315 Hourly counts for processed jobs from the past day.
316  
317 =back
318  
319 =head2 list_jobs
320  
321 my $results = $backend->list_jobs($offset, $limit);
322 my $results = $backend->list_jobs($offset, $limit, {states => ['inactive']});
323  
324 Returns the information about jobs in batches. Meant to be overloaded in a subclass.
325  
326 # Get the total number of results (without limit)
327 my $num = $backend->list_jobs(0, 100, {queues => ['important']})->{total};
328  
329 # Check job state
330 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
331 my $state = $results->{jobs}[0]{state};
332  
333 # Get job result
334 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
335 my $result = $results->{jobs}[0]{result};
336  
337 These options are currently available:
338  
339 =over 2
340  
341 =item before
342  
343 before => 23
344  
345 List only jobs before this id.
346  
347 =item ids
348  
349 ids => ['23', '24']
350  
351 List only jobs with these ids.
352  
353 =item notes
354  
355 notes => ['foo', 'bar']
356  
357 List only jobs with one of these notes.
358  
359 =item queues
360  
361 queues => ['important', 'unimportant']
362  
363 List only jobs in these queues.
364  
365 =item states
366  
367 states => ['inactive', 'active']
368  
369 List only jobs in these states.
370  
371 =item tasks
372  
373 tasks => ['foo', 'bar']
374  
375 List only jobs for these tasks.
376  
377 =back
378  
379 These fields are currently available:
380  
381 =over 2
382  
383 =item args
384  
385 args => ['foo', 'bar']
386  
387 Job arguments.
388  
389 =item attempts
390  
391 attempts => 25
392  
393 Number of times performing this job will be attempted.
394  
395 =item children
396  
397 children => ['10026', '10027', '10028']
398  
399 Jobs depending on this job.
400  
401 =item created
402  
403 created => 784111777
404  
405 Epoch time job was created.
406  
407 =item delayed
408  
409 delayed => 784111777
410  
411 Epoch time job was delayed to.
412  
413 =item expires
414  
415 expires => 784111777
416  
417 Epoch time job is valid until before it expires.
418  
419 =item finished
420  
421 finished => 784111777
422  
423 Epoch time job was finished.
424  
425 =item id
426  
427 id => 10025
428  
429 Job id.
430  
431 =item lax
432  
433 lax => 0
434  
435 Existing jobs this job depends on may also have failed to allow for it to be processed.
436  
437 =item notes
438  
439 notes => {foo => 'bar', baz => [1, 2, 3]}
440  
441 Hash reference with arbitrary metadata for this job.
442  
443 =item parents
444  
445 parents => ['10023', '10024', '10025']
446  
447 Jobs this job depends on.
448  
449 =item priority
450  
451 priority => 3
452  
453 Job priority.
454  
455 =item queue
456  
457 queue => 'important'
458  
459 Queue name.
460  
461 =item result
462  
463 result => 'All went well!'
464  
465 Job result.
466  
467 =item retried
468  
469 retried => 784111777
470  
471 Epoch time job has been retried.
472  
473 =item retries
474  
475 retries => 3
476  
477 Number of times job has been retried.
478  
479 =item started
480  
481 started => 784111777
482  
483 Epoch time job was started.
484  
485 =item state
486  
487 state => 'inactive'
488  
489 Current job state, usually C<active>, C<failed>, C<finished> or C<inactive>.
490  
491 =item task
492  
493 task => 'foo'
494  
495 Task name.
496  
497 =item time
498  
499 time => 78411177
500  
501 Server time.
502  
503 =item worker
504  
505 worker => '154'
506  
507 Id of worker that is processing the job.
508  
509 =back
510  
511 =head2 list_locks
512  
513 my $results = $backend->list_locks($offset, $limit);
514 my $results = $backend->list_locks($offset, $limit, {names => ['foo']});
515  
516 Returns information about locks in batches. Meant to be overloaded in a subclass.
517  
518 # Get the total number of results (without limit)
519 my $num = $backend->list_locks(0, 100, {names => ['bar']})->{total};
520  
521 # Check expiration time
522 my $results = $backend->list_locks(0, 1, {names => ['foo']});
523 my $expires = $results->{locks}[0]{expires};
524  
525 These options are currently available:
526  
527 =over 2
528  
529 =item names
530  
531 names => ['foo', 'bar']
532  
533 List only locks with these names.
534  
535 =back
536  
537 These fields are currently available:
538  
539 =over 2
540  
541 =item expires
542  
543 expires => 784111777
544  
545 Epoch time this lock will expire.
546  
547 =item id
548  
549 id => 1
550  
551 Lock id.
552  
553 =item name
554  
555 name => 'foo'
556  
557 Lock name.
558  
559 =back
560  
561 =head2 list_schedules
562  
563 my $results = $backend->list_schedules($offset, $limit);
564 my $results = $backend->list_schedules($offset, $limit, {names => ['daily']});
565  
566 Returns information about schedules in batches. Meant to be overloaded in a subclass.
567  
568 # Get the total number of results (without limit)
569 my $num = $backend->list_schedules(0, 100)->{total};
570  
571 # Check next firing time
572 my $results = $backend->list_schedules(0, 1, {names => ['daily']});
573 my $next = $results->{schedules}[0]{next_run};
574  
575 These options are currently available:
576  
577 =over 2
578  
579 =item before
580  
581 before => 23
582  
583 List only schedules before this id.
584  
585 =item ids
586  
587 ids => ['23', '24']
588  
589 List only schedules with these ids.
590  
591 =item names
592  
593 names => ['foo', 'bar']
594  
595 List only schedules with these names.
596  
597 =back
598  
599 These fields are currently available:
600  
601 =over 2
602  
603 =item args
604  
605 args => ['foo', 'bar']
606  
607 Job arguments used for each enqueued job.
608  
609 =item attempts
610  
611 attempts => 25
612  
613 Number of attempts each enqueued job will get.
614  
615 =item created
616  
617 created => 784111777
618  
619 Epoch time the schedule was created.
620  
621 =item cron
622  
623 cron => '0 9 * * 1-5'
624  
625 Cron expression.
626  
627 =item expire
628  
629 expire => 300
630  
631 Expiration in seconds for each enqueued job.
632  
633 =item id
634  
635 id => 23
636  
637 Schedule id.
638  
639 =item last_job
640  
641 last_job => '10025'
642  
643 Id of the most recently enqueued job, or C<undef> if the schedule has not fired yet.
644  
645 =item last_run
646  
647 last_run => 784111777
648  
649 Epoch time the schedule last fired, or C<undef> if it has not fired yet.
650  
651 =item lax
652  
653 lax => 0
654  
655 Lax dependency setting for each enqueued job.
656  
657 =item name
658  
659 name => 'daily'
660  
661 Schedule name.
662  
663 =item next_run
664  
665 next_run => 784111777
666  
667 Epoch time the schedule will fire next.
668  
669 =item notes
670  
671 notes => {foo => 'bar'}
672  
673 Hash reference with arbitrary metadata applied to each enqueued job.
674  
675 =item paused
676  
677 paused => 0
678  
679 True if the schedule is paused and will not fire.
680  
681 =item priority
682  
683 priority => 0
684  
685 Priority of each enqueued job.
686  
687 =item queue
688  
689 queue => 'default'
690  
691 Queue each enqueued job is placed in.
692  
693 =item task
694  
695 task => 'foo'
696  
697 Task name.
698  
699 =back
700  
701 =head2 list_workers
702  
703 my $results = $backend->list_workers($offset, $limit);
704 my $results = $backend->list_workers($offset, $limit, {ids => [23]});
705  
706 Returns information about workers in batches. Meant to be overloaded in a subclass.
707  
708 # Get the total number of results (without limit)
709 my $num = $backend->list_workers(0, 100)->{total};
710  
711 # Check worker host
712 my $results = $backend->list_workers(0, 1, {ids => [$worker_id]});
713 my $host = $results->{workers}[0]{host};
714  
715 These options are currently available:
716  
717 =over 2
718  
719 =item before
720  
721 before => 23
722  
723 List only workers before this id.
724  
725 =item ids
726  
727 ids => ['23', '24']
728  
729 List only workers with these ids.
730  
731 =back
732  
733 These fields are currently available:
734  
735 =over 2
736  
737 =item id
738  
739 id => 22
740  
741 Worker id.
742  
743 =item host
744  
745 host => 'localhost'
746  
747 Worker host.
748  
749 =item jobs
750  
751 jobs => ['10023', '10024', '10025', '10029']
752  
753 Ids of jobs the worker is currently processing.
754  
755 =item notified
756  
757 notified => 784111777
758  
759 Epoch time worker sent the last heartbeat.
760  
761 =item pid
762  
763 pid => 12345
764  
765 Process id of worker.
766  
767 =item started
768  
769 started => 784111777
770  
771 Epoch time worker was started.
772  
773 =item status
774  
775 status => {queues => ['default', 'important']}
776  
777 Hash reference with whatever status information the worker would like to share.
778  
779 =back
780  
781 =head2 lock
782  
783 my $bool = $backend->lock('foo', 3600);
784 my $bool = $backend->lock('foo', 3600, {limit => 20});
785  
786 Try to acquire a named lock that will expire automatically after the given amount of time in seconds. An expiration
787 time of C<0> can be used to check if a named lock already exists without creating one. Meant to be overloaded in a
788 subclass.
789  
790 These options are currently available:
791  
792 =over 2
793  
794 =item limit
795  
796 limit => 20
797  
798 Number of shared locks with the same name that can be active at the same time, defaults to C<1>.
799  
800 =back
801  
802 =head2 note
803  
804 my $bool = $backend->note($job_id, {mojo => 'rocks', minion => 'too'});
805  
806 Change one or more metadata fields for a job. Setting a value to C<undef> will remove the field. Meant to be overloaded
807 in a subclass.
808  
809 =head2 pause_schedule
810  
811 my $bool = $backend->pause_schedule('daily');
812  
813 Pause a schedule by name so it stops firing until resumed. Returns true on success, false if the schedule does not
814 exist. Meant to be overloaded in a subclass.
815  
816 =head2 receive
817  
818 my $commands = $backend->receive($worker_id);
819  
820 Receive remote control commands for worker. Meant to be overloaded in a subclass.
821  
822 =head2 register_worker
823  
824 my $worker_id = $backend->register_worker;
825 my $worker_id = $backend->register_worker($worker_id);
826 my $worker_id = $backend->register_worker(
827 $worker_id, {status => {queues => ['default', 'important']}});
828  
829 Register worker or send heartbeat to show that this worker is still alive. Meant to be overloaded in a subclass.
830  
831 These options are currently available:
832  
833 =over 2
834  
835 =item status
836  
837 status => {queues => ['default', 'important']}
838  
839 Hash reference with whatever status information the worker would like to share.
840  
841 =back
842  
843 =head2 remove_job
844  
845 my $bool = $backend->remove_job($job_id);
846  
847 Remove C<failed>, C<finished> or C<inactive> job from queue. Meant to be overloaded in a subclass.
848  
849 =head2 repair
850  
851 $backend->repair;
852  
853 Repair worker registry and job queue if necessary. Meant to be overloaded in a subclass.
854  
855 =head2 reset
856  
857 $backend->reset({all => 1});
858  
859 Reset job queue. Meant to be overloaded in a subclass.
860  
861 These options are currently available:
862  
863 =over 2
864  
865 =item all
866  
867 all => 1
868  
869 Reset everything.
870  
871 =item locks
872  
873 locks => 1
874  
875 Reset only locks.
876  
877 =back
878  
879 =head2 resume_schedule
880  
881 my $bool = $backend->resume_schedule('daily');
882  
883 Resume a previously paused schedule. Returns true on success, false if the schedule does not exist. Meant to be
884 overloaded in a subclass.
885  
886 =head2 retry_job
887  
888 my $bool = $backend->retry_job($job_id, $retries);
889 my $bool = $backend->retry_job($job_id, $retries, {delay => 10});
890  
891 Transition job back to C<inactive> state, already C<inactive> jobs may also be retried to change options. Meant to be
892 overloaded in a subclass.
893  
894 These options are currently available:
895  
896 =over 2
897  
898 =item attempts
899  
900 attempts => 25
901  
902 Number of times performing this job will be attempted.
903  
904 =item delay
905  
906 delay => 10
907  
908 Delay job for this many seconds (from now), defaults to C<0>.
909  
910 =item expire
911  
912 expire => 300
913  
914 Job is valid for this many seconds (from now) before it expires.
915  
916 =item lax
917  
918 lax => 1
919  
920 Existing jobs this job depends on may also have transitioned to the C<failed> state to allow for it to be processed,
921 defaults to C<false>.
922  
923 =item parents
924  
925 parents => [$id1, $id2, $id3]
926  
927 Jobs this job depends on.
928  
929 =item priority
930  
931 priority => 5
932  
933 Job priority.
934  
935 =item queue
936  
937 queue => 'important'
938  
939 Queue to put job in.
940  
941 =back
942  
943 =head2 schedule
944  
945 my $id = $backend->schedule('daily', '0 4 * * *', 'cleanup');
946 my $id = $backend->schedule('daily', '0 4 * * *', 'cleanup', [@args]);
947 my $id = $backend->schedule(
948 'daily', '0 4 * * *', 'cleanup', [@args], {priority => 5});
949  
950 Create or replace a schedule by unique name. The cron expression is parsed up front and the next firing time is
951 computed; the entry is rejected if the expression is invalid. Existing schedules with the same name are updated, but
952 the firing time is preserved if the cron expression has not changed. Meant to be overloaded in a subclass.
953  
954 These options are currently available:
955  
956 =over 2
957  
958 =item attempts
959  
960 attempts => 25
961  
962 Number of times performing each enqueued job will be attempted, with a delay based on L<Minion/"backoff"> after the
963 first attempt, defaults to C<1>.
964  
965 =item expire
966  
967 expire => 300
968  
969 Each enqueued job is valid for this many seconds (from enqueue time) before it expires.
970  
971 =item lax
972  
973 lax => 1
974  
975 Existing jobs each enqueued job depends on may also have transitioned to the C<failed> state to allow for it to be
976 processed, defaults to C<false>.
977  
978 =item notes
979  
980 notes => {foo => 'bar', baz => [1, 2, 3]}
981  
982 Hash reference with arbitrary metadata for each enqueued job.
983  
984 =item priority
985  
986 priority => 5
987  
988 Priority of each enqueued job, defaults to C<0>.
989  
990 =item queue
991  
992 queue => 'important'
993  
994 Queue to put each enqueued job in, defaults to C<default>.
995  
996 =back
997  
998 =head2 stats
999  
1000 my $stats = $backend->stats;
1001  
1002 Get statistics for the job queue. Meant to be overloaded in a subclass.
1003  
1004 These fields are currently available:
1005  
1006 =over 2
1007  
1008 =item active_jobs
1009  
1010 active_jobs => 100
1011  
1012 Number of jobs in C<active> state.
1013  
1014 =item active_locks
1015  
1016 active_locks => 100
1017  
1018 Number of active named locks.
1019  
1020 =item active_workers
1021  
1022 active_workers => 100
1023  
1024 Number of workers that are currently processing a job.
1025  
1026 =item delayed_jobs
1027  
1028 delayed_jobs => 100
1029  
1030 Number of jobs in C<inactive> state that are scheduled to run at specific time in the future or have unresolved
1031 dependencies.
1032  
1033 =item enqueued_jobs
1034  
1035 enqueued_jobs => 100000
1036  
1037 Rough estimate of how many jobs have ever been enqueued.
1038  
1039 =item failed_jobs
1040  
1041 failed_jobs => 100
1042  
1043 Number of jobs in C<failed> state.
1044  
1045 =item finished_jobs
1046  
1047 finished_jobs => 100
1048  
1049 Number of jobs in C<finished> state.
1050  
1051 =item inactive_jobs
1052  
1053 inactive_jobs => 100
1054  
1055 Number of jobs in C<inactive> state.
1056  
1057 =item inactive_schedules
1058  
1059 inactive_schedules => 100
1060  
1061 Number of schedules that are currently paused.
1062  
1063 =item inactive_workers
1064  
1065 inactive_workers => 100
1066  
1067 Number of workers that are currently not processing a job.
1068  
1069 =item schedules
1070  
1071 schedules => 100
1072  
1073 Number of schedules that are currently active.
1074  
1075 =item uptime
1076  
1077 uptime => 1000
1078  
1079 Uptime in seconds.
1080  
1081 =item workers
1082  
1083 workers => 200;
1084  
1085 Number of registered workers.
1086  
1087 =back
1088  
1089 =head2 unlock
1090  
1091 my $bool = $backend->unlock('foo');
1092  
1093 Release a named lock. Meant to be overloaded in a subclass.
1094  
1095 =head2 unregister_worker
1096  
1097 $backend->unregister_worker($worker_id);
1098  
1099 Unregister worker. Meant to be overloaded in a subclass.
1100  
1101 =head2 unschedule
1102  
1103 my $bool = $backend->unschedule('daily');
1104  
1105 Remove a schedule by name. Returns true on success, false if the schedule does not exist. Meant to be overloaded in a
1106 subclass.
1107  
1108 =head1 SEE ALSO
1109  
1110 L<Minion>, L<Minion::Guide>, L<https://minion.pm>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
1111  
1112 =cut
« Minion/Command/minion/worker.pm ↑ Summary Mojolicious/Plugin/Minion.pm »