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

BUGS

575       Report any issues on the public bugtracker.
576

AUTHOR

578       Dan Book <dbook@cpan.org>
579
581       This software is Copyright (c) 2015 by Dan Book.
582
583       This is free software, licensed under:
584
585         The Artistic License 2.0 (GPL Compatible)
586

SEE ALSO

588       Minion, Mojo::SQLite
589
590
591
592perl v5.30.1                      2020-01-30      Minion::Backend::SQLite(3pm)
Impressum