1Minion::Backend::SQLiteU(s3eprm)Contributed Perl DocumenMtiantiioonn::Backend::SQLite(3pm)
2
3
4

NAME

6       Minion::Backend::SQLite - SQLite backend for Minion job queue
7

SYNOPSIS

9         use Minion::Backend::SQLite;
10         my $backend = Minion::Backend::SQLite->new('sqlite:test.db');
11
12         # Minion
13         use Minion;
14         my $minion = Minion->new(SQLite => 'sqlite:test.db');
15
16         # Mojolicious (via Mojolicious::Plugin::Minion)
17         $self->plugin(Minion => { SQLite => 'sqlite:test.db' });
18
19         # Mojolicious::Lite (via Mojolicious::Plugin::Minion)
20         plugin Minion => { SQLite => 'sqlite:test.db' };
21
22         # Share the database connection cache
23         helper sqlite => sub { state $sqlite = Mojo::SQLite->new('sqlite:test.db') };
24         plugin Minion => { SQLite => app->sqlite };
25

DESCRIPTION

27       Minion::Backend::SQLite is a backend for Minion based on Mojo::SQLite.
28       All necessary tables will be created automatically with a set of
29       migrations named "minion". If no connection string or ":temp:" is
30       provided, the database will be created in a temporary directory.
31

ATTRIBUTES

33       Minion::Backend::SQLite inherits all attributes from Minion::Backend
34       and implements the following new ones.
35
36   dequeue_interval
37         my $seconds = $backend->dequeue_interval;
38         $backend    = $backend->dequeue_interval($seconds);
39
40       Interval in seconds between "dequeue" attempts. Defaults to 0.5.
41
42   sqlite
43         my $sqlite = $backend->sqlite;
44         $backend   = $backend->sqlite(Mojo::SQLite->new);
45
46       Mojo::SQLite object used to store all data.
47

METHODS

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

BUGS

634       Report any issues on the public bugtracker.
635

AUTHOR

637       Dan Book <dbook@cpan.org>
638
640       This software is Copyright (c) 2015 by Dan Book.
641
642       This is free software, licensed under:
643
644         The Artistic License 2.0 (GPL Compatible)
645

SEE ALSO

647       Minion, Mojo::SQLite
648
649
650
651perl v5.32.1                      2021-01-27      Minion::Backend::SQLite(3pm)
Impressum