1Minion::Backend::SQLiteU(s3e)r Contributed Perl DocumentaMtiinoinon::Backend::SQLite(3)
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       worker
311           worker => '154'
312
313         Id of worker that is processing the job.
314
315   list_locks
316         my $results = $backend->list_locks($offset, $limit);
317         my $results = $backend->list_locks($offset, $limit, {names => ['foo']});
318
319       Returns information about locks in batches.
320
321         # Get the total number of results (without limit)
322         my $num = $backend->list_locks(0, 100, {names => ['bar']})->{total};
323
324         # Check expiration time
325         my $results = $backend->list_locks(0, 1, {names => ['foo']});
326         my $expires = $results->{locks}[0]{expires};
327
328       These options are currently available:
329
330       names
331           names => ['foo', 'bar']
332
333         List only locks with these names.
334
335       These fields are currently available:
336
337       expires
338           expires => 784111777
339
340         Epoch time this lock will expire.
341
342       name
343           name => 'foo'
344
345         Lock name.
346
347   list_workers
348         my $results = $backend->list_workers($offset, $limit);
349         my $results = $backend->list_workers($offset, $limit, {ids => [23]});
350
351       Returns information about workers in batches.
352
353         # Get the total number of results (without limit)
354         my $num = $backend->list_workers(0, 100)->{total};
355
356         # Check worker host
357         my $results = $backend->list_workers(0, 1, {ids => [$worker_id]});
358         my $host    = $results->{workers}[0]{host};
359
360       These options are currently available:
361
362       ids
363           ids => ['23', '24']
364
365         List only workers with these ids.
366
367       These fields are currently available:
368
369       id
370           id => 22
371
372         Worker id.
373
374       host
375           host => 'localhost'
376
377         Worker host.
378
379       jobs
380           jobs => ['10023', '10024', '10025', '10029']
381
382         Ids of jobs the worker is currently processing.
383
384       notified
385           notified => 784111777
386
387         Epoch time worker sent the last heartbeat.
388
389       pid
390           pid => 12345
391
392         Process id of worker.
393
394       started
395           started => 784111777
396
397         Epoch time worker was started.
398
399       status
400           status => {queues => ['default', 'important']}
401
402         Hash reference with whatever status information the worker would like
403         to share.
404
405   lock
406         my $bool = $backend->lock('foo', 3600);
407         my $bool = $backend->lock('foo', 3600, {limit => 20});
408
409       Try to acquire a named lock that will expire automatically after the
410       given amount of time in seconds. An expiration time of 0 can be used to
411       check if a named lock already exists without creating one.
412
413       These options are currently available:
414
415       limit
416           limit => 20
417
418         Number of shared locks with the same name that can be active at the
419         same time, defaults to 1.
420
421   note
422         my $bool = $backend->note($job_id, {mojo => 'rocks', minion => 'too'});
423
424       Change one or more metadata fields for a job. It is currently an error
425       to attempt to set a metadata field with a name containing the
426       characters ".", "[", or "]".
427
428   receive
429         my $commands = $backend->receive($worker_id);
430
431       Receive remote control commands for worker.
432
433   register_worker
434         my $worker_id = $backend->register_worker;
435         my $worker_id = $backend->register_worker($worker_id);
436         my $worker_id = $backend->register_worker(
437           $worker_id, {status => {queues => ['default', 'important']}});
438
439       Register worker or send heartbeat to show that this worker is still
440       alive.
441
442       These options are currently available:
443
444       status
445           status => {queues => ['default', 'important']}
446
447         Hash reference with whatever status information the worker would like
448         to share.
449
450   remove_job
451         my $bool = $backend->remove_job($job_id);
452
453       Remove "failed", "finished" or "inactive" job from queue.
454
455   repair
456         $backend->repair;
457
458       Repair worker registry and job queue if necessary.
459
460   reset
461         $backend->reset;
462
463       Reset job queue.
464
465   retry_job
466         my $bool = $backend->retry_job($job_id, $retries);
467         my $bool = $backend->retry_job($job_id, $retries, {delay => 10});
468
469       Transition job back to "inactive" state, already "inactive" jobs may
470       also be retried to change options.
471
472       These options are currently available:
473
474       attempts
475           attempts => 25
476
477         Number of times performing this job will be attempted.
478
479       delay
480           delay => 10
481
482         Delay job for this many seconds (from now).
483
484       parents
485           parents => [$id1, $id2, $id3]
486
487         Jobs this job depends on.
488
489       priority
490           priority => 5
491
492         Job priority.
493
494       queue
495           queue => 'important'
496
497         Queue to put job in.
498
499   stats
500         my $stats = $backend->stats;
501
502       Get statistics for the job queue.
503
504       These fields are currently available:
505
506       active_jobs
507           active_jobs => 100
508
509         Number of jobs in "active" state.
510
511       active_locks
512           active_locks => 100
513
514         Number of active named locks.
515
516       active_workers
517           active_workers => 100
518
519         Number of workers that are currently processing a job.
520
521       delayed_jobs
522           delayed_jobs => 100
523
524         Number of jobs in "inactive" state that are scheduled to run at
525         specific time in the future. Note that this field is EXPERIMENTAL and
526         might change without warning!
527
528       enqueued_jobs
529           enqueued_jobs => 100000
530
531         Rough estimate of how many jobs have ever been enqueued. Note that
532         this field is EXPERIMENTAL and might change without warning!
533
534       failed_jobs
535           failed_jobs => 100
536
537         Number of jobs in "failed" state.
538
539       finished_jobs
540           finished_jobs => 100
541
542         Number of jobs in "finished" state.
543
544       inactive_jobs
545           inactive_jobs => 100
546
547         Number of jobs in "inactive" state.
548
549       inactive_workers
550           inactive_workers => 100
551
552         Number of workers that are currently not processing a job.
553
554       uptime
555           uptime => undef
556
557         Uptime in seconds. Always undefined for SQLite.
558
559   unlock
560         my $bool = $backend->unlock('foo');
561
562       Release a named lock.
563
564   unregister_worker
565         $backend->unregister_worker($worker_id);
566
567       Unregister worker.
568

BUGS

570       Report any issues on the public bugtracker.
571

AUTHOR

573       Dan Book <dbook@cpan.org>
574
576       This software is Copyright (c) 2015 by Dan Book.
577
578       This is free software, licensed under:
579
580         The Artistic License 2.0 (GPL Compatible)
581

SEE ALSO

583       Minion, Mojo::SQLite
584
585
586
587perl v5.28.1                      2019-02-02        Minion::Backend::SQLite(3)
Impressum