Debian Codegraph @

README

raw
1 NAME
2
3 Minion::Backend::SQLite - SQLite backend for Minion job queue
4
5 SYNOPSIS
6
7 use Minion::Backend::SQLite;
8 my $backend = Minion::Backend::SQLite->new('sqlite:test.db');
9
10 # Minion
11 use Minion;
12 my $minion = Minion->new(SQLite => 'sqlite:test.db');
13
14 # Mojolicious (via Mojolicious::Plugin::Minion)
15 $self->plugin(Minion => { SQLite => 'sqlite:test.db' });
16
17 # Mojolicious::Lite (via Mojolicious::Plugin::Minion)
18 plugin Minion => { SQLite => 'sqlite:test.db' };
19
20 # Share the database connection cache
21 helper sqlite => sub { state $sqlite = Mojo::SQLite->new('sqlite:test.db') };
22 plugin Minion => { SQLite => app->sqlite };
23
24 DESCRIPTION
25
26 Minion::Backend::SQLite is a backend for Minion based on Mojo::SQLite.
27 All necessary tables will be created automatically with a set of
28 migrations named minion. If no connection string or :temp: is provided,
29 the database will be created in a temporary directory.
30
31 ATTRIBUTES
32
33 Minion::Backend::SQLite inherits all attributes from Minion::Backend
34 and implements the following new ones.
35
36 dequeue_interval
37
38 my $seconds = $backend->dequeue_interval;
39 $backend = $backend->dequeue_interval($seconds);
40
41 Interval in seconds between "dequeue" attempts. Defaults to 0.5.
42
43 sqlite
44
45 my $sqlite = $backend->sqlite;
46 $backend = $backend->sqlite(Mojo::SQLite->new);
47
48 Mojo::SQLite object used to store all data.
49
50 METHODS
51
52 Minion::Backend::SQLite inherits all methods from Minion::Backend and
53 implements the following new ones.
54
55 new
56
57 my $backend = Minion::Backend::SQLite->new;
58 my $backend = Minion::Backend::SQLite->new(':temp:');
59 my $backend = Minion::Backend::SQLite->new('sqlite:test.db');
60 my $backend = Minion::Backend::SQLite->new->tap(sub { $_->sqlite->from_filename('C:\\foo\\bar.db') });
61 my $backend = Minion::Backend::SQLite->new(Mojo::SQLite->new);
62
63 Construct a new Minion::Backend::SQLite object.
64
65 broadcast
66
67 my $bool = $backend->broadcast('some_command');
68 my $bool = $backend->broadcast('some_command', [@args]);
69 my $bool = $backend->broadcast('some_command', [@args], [$id1, $id2, $id3]);
70
71 Broadcast remote control command to one or more workers.
72
73 dequeue
74
75 my $job_info = $backend->dequeue($worker_id, 0.5);
76 my $job_info = $backend->dequeue($worker_id, 0.5, {queues => ['important']});
77
78 Wait a given amount of time in seconds for a job, dequeue it and
79 transition from inactive to active state, or return undef if queues
80 were empty. Jobs will be checked for in intervals defined by
81 "dequeue_interval" until the timeout is reached.
82
83 These options are currently available:
84
85 id
86
87 id => '10023'
88
89 Dequeue a specific job.
90
91 min_priority
92
93 min_priority => 3
94
95 Do not dequeue jobs with a lower priority.
96
97 queues
98
99 queues => ['important']
100
101 One or more queues to dequeue jobs from, defaults to default.
102
103 These fields are currently available:
104
105 args
106
107 args => ['foo', 'bar']
108
109 Job arguments.
110
111 id
112
113 id => '10023'
114
115 Job ID.
116
117 retries
118
119 retries => 3
120
121 Number of times job has been retried.
122
123 task
124
125 task => 'foo'
126
127 Task name.
128
129 enqueue
130
131 my $job_id = $backend->enqueue('foo');
132 my $job_id = $backend->enqueue(foo => [@args]);
133 my $job_id = $backend->enqueue(foo => [@args] => {priority => 1});
134
135 Enqueue a new job with inactive state.
136
137 These options are currently available:
138
139 attempts
140
141 attempts => 25
142
143 Number of times performing this job will be attempted, with a delay
144 based on "backoff" in Minion after the first attempt, defaults to 1.
145
146 delay
147
148 delay => 10
149
150 Delay job for this many seconds (from now).
151
152 expire
153
154 expire => 300
155
156 Job is valid for this many seconds (from now) before it expires. Note
157 that this option is EXPERIMENTAL and might change without warning!
158
159 lax
160
161 lax => 1
162
163 Existing jobs this job depends on may also have transitioned to the
164 failed state to allow for it to be processed, defaults to false. Note
165 that this option is EXPERIMENTAL and might change without warning!
166
167 notes
168
169 notes => {foo => 'bar', baz => [1, 2, 3]}
170
171 Hash reference with arbitrary metadata for this job.
172
173 parents
174
175 parents => [$id1, $id2, $id3]
176
177 One or more existing jobs this job depends on, and that need to have
178 transitioned to the state finished before it can be processed.
179
180 priority
181
182 priority => 5
183
184 Job priority, defaults to 0. Jobs with a higher priority get
185 performed first.
186
187 queue
188
189 queue => 'important'
190
191 Queue to put job in, defaults to default.
192
193 fail_job
194
195 my $bool = $backend->fail_job($job_id, $retries);
196 my $bool = $backend->fail_job($job_id, $retries, 'Something went wrong!');
197 my $bool = $backend->fail_job(
198 $job_id, $retries, {msg => 'Something went wrong!'});
199
200 Transition from active to failed state with or without a result, and if
201 there are attempts remaining, transition back to inactive with an
202 exponentially increasing delay based on "backoff" in Minion.
203
204 finish_job
205
206 my $bool = $backend->finish_job($job_id, $retries);
207 my $bool = $backend->finish_job($job_id, $retries, 'All went well!');
208 my $bool = $backend->finish_job($job_id, $retries, {msg => 'All went well!'});
209
210 Transition from active to finished state with or without a result.
211
212 history
213
214 my $history = $backend->history;
215
216 Get history information for job queue.
217
218 These fields are currently available:
219
220 daily
221
222 daily => [{epoch => 12345, finished_jobs => 95, failed_jobs => 2}, ...]
223
224 Hourly counts for processed jobs from the past day.
225
226 list_jobs
227
228 my $results = $backend->list_jobs($offset, $limit);
229 my $results = $backend->list_jobs($offset, $limit, {states => ['inactive']});
230
231 Returns the information about jobs in batches.
232
233 # Get the total number of results (without limit)
234 my $num = $backend->list_jobs(0, 100, {queues => ['important']})->{total};
235
236 # Check job state
237 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
238 my $state = $results->{jobs}[0]{state};
239
240 # Get job result
241 my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
242 my $result = $results->{jobs}[0]{result};
243
244 These options are currently available:
245
246 before
247
248 before => 23
249
250 List only jobs before this id.
251
252 ids
253
254 ids => ['23', '24']
255
256 List only jobs with these ids.
257
258 queues
259
260 queues => ['important', 'unimportant']
261
262 List only jobs in these queues.
263
264 states
265
266 states => ['inactive', 'active']
267
268 List only jobs in these states.
269
270 tasks
271
272 tasks => ['foo', 'bar']
273
274 List only jobs for these tasks.
275
276 These fields are currently available:
277
278 args
279
280 args => ['foo', 'bar']
281
282 Job arguments.
283
284 attempts
285
286 attempts => 25
287
288 Number of times performing this job will be attempted.
289
290 children
291
292 children => ['10026', '10027', '10028']
293
294 Jobs depending on this job.
295
296 created
297
298 created => 784111777
299
300 Epoch time job was created.
301
302 delayed
303
304 delayed => 784111777
305
306 Epoch time job was delayed to.
307
308 expires
309
310 expires => 784111777
311
312 Epoch time job is valid until before it expires.
313
314 finished
315
316 finished => 784111777
317
318 Epoch time job was finished.
319
320 id
321
322 id => 10025
323
324 Job id.
325
326 lax
327
328 lax => 0
329
330 Existing jobs this job depends on may also have failed to allow for
331 it to be processed.
332
333 notes
334
335 notes => {foo => 'bar', baz => [1, 2, 3]}
336
337 Hash reference with arbitrary metadata for this job.
338
339 parents
340
341 parents => ['10023', '10024', '10025']
342
343 Jobs this job depends on.
344
345 priority
346
347 priority => 3
348
349 Job priority.
350
351 queue
352
353 queue => 'important'
354
355 Queue name.
356
357 result
358
359 result => 'All went well!'
360
361 Job result.
362
363 retried
364
365 retried => 784111777
366
367 Epoch time job has been retried.
368
369 retries
370
371 retries => 3
372
373 Number of times job has been retried.
374
375 started
376
377 started => 784111777
378
379 Epoch time job was started.
380
381 state
382
383 state => 'inactive'
384
385 Current job state, usually active, failed, finished or inactive.
386
387 task
388
389 task => 'foo'
390
391 Task name.
392
393 time
394
395 time => 78411177
396
397 Current time.
398
399 worker
400
401 worker => '154'
402
403 Id of worker that is processing the job.
404
405 list_locks
406
407 my $results = $backend->list_locks($offset, $limit);
408 my $results = $backend->list_locks($offset, $limit, {names => ['foo']});
409
410 Returns information about locks in batches.
411
412 # Get the total number of results (without limit)
413 my $num = $backend->list_locks(0, 100, {names => ['bar']})->{total};
414
415 # Check expiration time
416 my $results = $backend->list_locks(0, 1, {names => ['foo']});
417 my $expires = $results->{locks}[0]{expires};
418
419 These options are currently available:
420
421 names
422
423 names => ['foo', 'bar']
424
425 List only locks with these names.
426
427 These fields are currently available:
428
429 expires
430
431 expires => 784111777
432
433 Epoch time this lock will expire.
434
435 name
436
437 name => 'foo'
438
439 Lock name.
440
441 list_workers
442
443 my $results = $backend->list_workers($offset, $limit);
444 my $results = $backend->list_workers($offset, $limit, {ids => [23]});
445
446 Returns information about workers in batches.
447
448 # Get the total number of results (without limit)
449 my $num = $backend->list_workers(0, 100)->{total};
450
451 # Check worker host
452 my $results = $backend->list_workers(0, 1, {ids => [$worker_id]});
453 my $host = $results->{workers}[0]{host};
454
455 These options are currently available:
456
457 before
458
459 before => 23
460
461 List only workers before this id.
462
463 ids
464
465 ids => ['23', '24']
466
467 List only workers with these ids.
468
469 These fields are currently available:
470
471 id
472
473 id => 22
474
475 Worker id.
476
477 host
478
479 host => 'localhost'
480
481 Worker host.
482
483 jobs
484
485 jobs => ['10023', '10024', '10025', '10029']
486
487 Ids of jobs the worker is currently processing.
488
489 notified
490
491 notified => 784111777
492
493 Epoch time worker sent the last heartbeat.
494
495 pid
496
497 pid => 12345
498
499 Process id of worker.
500
501 started
502
503 started => 784111777
504
505 Epoch time worker was started.
506
507 status
508
509 status => {queues => ['default', 'important']}
510
511 Hash reference with whatever status information the worker would like
512 to share.
513
514 lock
515
516 my $bool = $backend->lock('foo', 3600);
517 my $bool = $backend->lock('foo', 3600, {limit => 20});
518
519 Try to acquire a named lock that will expire automatically after the
520 given amount of time in seconds. An expiration time of 0 can be used to
521 check if a named lock already exists without creating one.
522
523 These options are currently available:
524
525 limit
526
527 limit => 20
528
529 Number of shared locks with the same name that can be active at the
530 same time, defaults to 1.
531
532 note
533
534 my $bool = $backend->note($job_id, {mojo => 'rocks', minion => 'too'});
535
536 Change one or more metadata fields for a job. Setting a value to undef
537 will remove the field. It is currently an error to attempt to set a
538 metadata field with a name containing the characters ., [, or ].
539
540 receive
541
542 my $commands = $backend->receive($worker_id);
543
544 Receive remote control commands for worker.
545
546 register_worker
547
548 my $worker_id = $backend->register_worker;
549 my $worker_id = $backend->register_worker($worker_id);
550 my $worker_id = $backend->register_worker(
551 $worker_id, {status => {queues => ['default', 'important']}});
552
553 Register worker or send heartbeat to show that this worker is still
554 alive.
555
556 These options are currently available:
557
558 status
559
560 status => {queues => ['default', 'important']}
561
562 Hash reference with whatever status information the worker would like
563 to share.
564
565 remove_job
566
567 my $bool = $backend->remove_job($job_id);
568
569 Remove failed, finished or inactive job from queue.
570
571 repair
572
573 $backend->repair;
574
575 Repair worker registry and job queue if necessary.
576
577 reset
578
579 $backend->reset({all => 1});
580
581 Reset job queue.
582
583 These options are currently available:
584
585 all
586
587 all => 1
588
589 Reset everything.
590
591 locks
592
593 locks => 1
594
595 Reset only locks.
596
597 retry_job
598
599 my $bool = $backend->retry_job($job_id, $retries);
600 my $bool = $backend->retry_job($job_id, $retries, {delay => 10});
601
602 Transition job back to inactive state, already inactive jobs may also
603 be retried to change options.
604
605 These options are currently available:
606
607 attempts
608
609 attempts => 25
610
611 Number of times performing this job will be attempted.
612
613 delay
614
615 delay => 10
616
617 Delay job for this many seconds (from now).
618
619 expire
620
621 expire => 300
622
623 Job is valid for this many seconds (from now) before it expires. Note
624 that this option is EXPERIMENTAL and might change without warning!
625
626 lax
627
628 lax => 1
629
630 Existing jobs this job depends on may also have transitioned to the
631 failed state to allow for it to be processed, defaults to false. Note
632 that this option is EXPERIMENTAL and might change without warning!
633
634 parents
635
636 parents => [$id1, $id2, $id3]
637
638 Jobs this job depends on.
639
640 priority
641
642 priority => 5
643
644 Job priority.
645
646 queue
647
648 queue => 'important'
649
650 Queue to put job in.
651
652 stats
653
654 my $stats = $backend->stats;
655
656 Get statistics for the job queue.
657
658 These fields are currently available:
659
660 active_jobs
661
662 active_jobs => 100
663
664 Number of jobs in active state.
665
666 active_locks
667
668 active_locks => 100
669
670 Number of active named locks.
671
672 active_workers
673
674 active_workers => 100
675
676 Number of workers that are currently processing a job.
677
678 delayed_jobs
679
680 delayed_jobs => 100
681
682 Number of jobs in inactive state that are scheduled to run at
683 specific time in the future.
684
685 enqueued_jobs
686
687 enqueued_jobs => 100000
688
689 Rough estimate of how many jobs have ever been enqueued.
690
691 failed_jobs
692
693 failed_jobs => 100
694
695 Number of jobs in failed state.
696
697 finished_jobs
698
699 finished_jobs => 100
700
701 Number of jobs in finished state.
702
703 inactive_jobs
704
705 inactive_jobs => 100
706
707 Number of jobs in inactive state.
708
709 inactive_workers
710
711 inactive_workers => 100
712
713 Number of workers that are currently not processing a job.
714
715 uptime
716
717 uptime => undef
718
719 Uptime in seconds. Always undefined for SQLite.
720
721 workers
722
723 workers => 200;
724
725 Number of registered workers.
726
727 unlock
728
729 my $bool = $backend->unlock('foo');
730
731 Release a named lock.
732
733 unregister_worker
734
735 $backend->unregister_worker($worker_id);
736
737 Unregister worker.
738
739 BUGS
740
741 Report any issues on the public bugtracker.
742
743 AUTHOR
744
745 Dan Book <[email protected]>
746
747 COPYRIGHT AND LICENSE
748
749 This software is Copyright (c) 2015 by Dan Book.
750
751 This is free software, licensed under:
752
753 The Artistic License 2.0 (GPL Compatible)
754
755 SEE ALSO
756
757 Minion, Mojo::SQLite
758