Minion...:SQLite(3pm)
πΈ NAME πΈ
Minion::Backend::SQLite β SQLite backend for Minion job queue. This is the Minion...:SQLite(3pm) page from User Contributed Perl Documentation, bestie. π
β¨ SYNOPSIS β¨
Okay so hereβs the whole βhow do I even use thisβ vibe check, no cap:
use Minion::Backend::SQLite;
my $backend = Minion::Backend::SQLite->new('sqlite:test.db');
# Minion
use Minion;
my $minion = Minion->new(SQLite => 'sqlite:test.db');
# Mojolicious (via Mojolicious::Plugin::Minion)
$self->plugin(Minion => { SQLite => 'sqlite:test.db' });
# Mojolicious::Lite (via Mojolicious::Plugin::Minion)
plugin Minion => { SQLite => 'sqlite:test.db' };
# Share the database connection cache
helper sqlite => sub { state $sqlite = Mojo::SQLite->new('sqlite:test.db') };
plugin Minion => { SQLite => app->sqlite };
π¦ DESCRIPTION π¦
Minion::Backend::SQLite is a backend for Minion based on Mojo::SQLite. π«Ά
All necessary tables will be created automatically with a set of migrations named "minion". If no connection string or ":temp:" is provided, the database will be created in a temporary directory. Lowkey magical, highkey useful. β¨
π ATTRIBUTES π
Minion::Backend::SQLite inherits all attributes from Minion::Backend and implements the following new ones, bestie:
π
dequeue_interval
my $seconds = $backend->dequeue_interval;
$backend = $backend->dequeue_interval($seconds);
Interval in seconds between "dequeue" attempts. Defaults to 0.5. β±οΈ
π
sqlite
my $sqlite = $backend->sqlite;
$backend = $backend->sqlite(Mojo::SQLite->new);
Mojo::SQLite object used to store all data. Iconic little database holder. π
π§ METHODS π§
Minion::Backend::SQLite inherits all methods from Minion::Backend and implements the following new ones:
π new
my $backend = Minion::Backend::SQLite->new;
my $backend = Minion::Backend::SQLite->new(':temp:');
my $backend = Minion::Backend::SQLite->new('sqlite:test.db');
my $backend = Minion::Backend::SQLite->new->tap(sub { $_->sqlite->from_filename('C:\\foo\\bar.db') });
my $backend = Minion::Backend::SQLite->new(Mojo::SQLite->new);
Construct a new Minion::Backend::SQLite object. Fresh backend, fresh vibes. π
π₯ broadcast
my $bool = $backend->broadcast('some_command');
my $bool = $backend->broadcast('some_command', [@args]);
my $bool = $backend->broadcast('some_command', [@args], [$id1, $id2, $id3]);
Broadcast remote control command to one or more workers. Itβs giving βgroup chat but for workers.β π£
π dequeue
my $job_info = $backend->dequeue($worker_id, 0.5);
my $job_info = $backend->dequeue($worker_id, 0.5, {queues => ['important']});
Wait a given amount of time in seconds for a job, dequeue it and transition from "inactive" to "active" state, or return "undef" if queues were empty. Jobs will be checked for in intervals defined by "dequeue_interval" until the timeout is reached. Obsessed with a queue that actually checks itself. π
These options are currently available:
idβ dequeue a specific job. Example:id => '10023'min_priorityβ do not dequeue jobs with a lower priority. Example:min_priority => 3queuesβ one or more queues to dequeue jobs from, defaults to"default". Example:queues => ['important']
These fields are currently available:
argsβ job arguments. Example:args => ['foo', 'bar']idβ job ID. Example:id => '10023'retriesβ number of times job has been retried. Example:retries => 3taskβ task name. Example:task => 'foo'
πΈ enqueue
my $job_id = $backend->enqueue('foo');
my $job_id = $backend->enqueue(foo => [@args]);
my $job_id = $backend->enqueue(foo => [@args] => {priority => 1});
Enqueue a new job with "inactive" state. New job just dropped. π
These options are currently available:
attemptsβ number of times performing this job will be attempted, with a delay based on"backoff"in Minion after the first attempt, defaults to1. Example:attempts => 25delayβ delay job for this many seconds (from now). Example:delay => 10expireβ job is valid for this many seconds (from now) before it expires. Example:expire => 300
β οΈ Note that this option is EXPERIMENTAL and might change without warning!
laxβ existing jobs this job depends on may also have transitioned to the"failed"state to allow for it to be processed, defaults to"false". Example:lax => 1
β οΈ Note that this option is EXPERIMENTAL and might change without warning!
notesβ hash reference with arbitrary metadata for this job. Example:notes => {foo => 'bar', baz => [1, 2, 3]}parentsβ one or more existing jobs this job depends on, and that need to have transitioned to the state"finished"before it can be processed. Example:parents => [$id1, $id2, $id3]priorityβ job priority, defaults to0. Jobs with a higher priority get performed first. Example:priority => 5queueβ queue to put job in, defaults to"default". Example:queue => 'important'
π fail_job
my $bool = $backend->fail_job($job_id, $retries);
my $bool = $backend->fail_job($job_id, $retries, 'Something went wrong!');
my $bool = $backend->fail_job(
$job_id, $retries, {msg => 'Something went wrong!'});
Transition from "active" to "failed" state with or without a result, and if there are attempts remaining, transition back to "inactive" with an exponentially increasing delay based on "backoff" in Minion. Not the slay we wanted, but the retry math is doing its thing. π
π¦ finish_job
my $bool = $backend->finish_job($job_id, $retries);
my $bool = $backend->finish_job($job_id, $retries, 'All went well!');
my $bool = $backend->finish_job($job_id, $retries, {msg => 'All went well!'});
Transition from "active" to "finished" state with or without a result. Ate and left no crumbs. β
β history
my $history = $backend->history;
Get history information for job queue. Itβs giving receipts, but make it job stats. π§Ύ
These fields are currently available:
dailyβ hourly counts for processed jobs from the past day. Example:daily => [{epoch => 12345, finished_jobs => 95, failed_jobs => 2}, ...]
π list_jobs
my $results = $backend->list_jobs($offset, $limit);
my $results = $backend->list_jobs($offset, $limit, {states => ['inactive']});
Returns the information about jobs in batches. Batch it up, bestie. π
# Get the total number of results (without limit)
my $num = $backend->list_jobs(0, 100, {queues => ['important']})->{total};
# Check job state
my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
my $state = $results->{jobs}[0]{state};
# Get job result
my $results = $backend->list_jobs(0, 1, {ids => [$job_id]});
my $result = $results->{jobs}[0]{result};
These options are currently available:
beforeβ list only jobs before this id. Example:before => 23idsβ list only jobs with these ids. Example:ids => ['23', '24']queuesβ list only jobs in these queues. Example:queues => ['important', 'unimportant']statesβ list only jobs in these states. Example:states => ['inactive', 'active']tasksβ list only jobs for these tasks. Example:tasks => ['foo', 'bar']
These fields are currently available:
argsβ job arguments. Example:args => ['foo', 'bar']attemptsβ number of times performing this job will be attempted. Example:attempts => 25childrenβ jobs depending on this job. Example:children => ['10026', '10027', '10028']createdβ epoch time job was created. Example:created => 784111777delayedβ epoch time job was delayed to. Example:delayed => 784111777expiresβ epoch time job is valid until before it expires. Example:expires => 784111777finishedβ epoch time job was finished. Example:finished => 784111777idβ job id. Example:id => 10025laxβ existing jobs this job depends on may also have failed to allow for it to be processed. Example:lax => 0notesβ hash reference with arbitrary metadata for this job. Example:notes => {foo => 'bar', baz => [1, 2, 3]}parentsβ jobs this job depends on. Example:parents => ['10023', '10024', '10025']priorityβ job priority. Example:priority => 3queueβ queue name. Example:queue => 'important'resultβ job result. Example:result => 'All went well!'retriedβ epoch time job has been retried. Example:retried => 784111777retriesβ number of times job has been retried. Example:retries => 3startedβ epoch time job was started. Example:started => 784111777stateβ current job state, usually"active","failed","finished"or"inactive". Example:state => 'inactive'taskβ task name. Example:task => 'foo'timeβ current time. Example:time => 78411177workerβ id of worker that is processing the job. Example:worker => '154'
π list_locks
my $results = $backend->list_locks($offset, $limit);
my $results = $backend->list_locks($offset, $limit, {names => ['foo']});
Returns information about locks in batches. Locked in, literally. π
# Get the total number of results (without limit)
my $num = $backend->list_locks(0, 100, {names => ['bar']})->{total};
# Check expiration time
my $results = $backend->list_locks(0, 1, {names => ['foo']});
my $expires = $results->{locks}[0]{expires};
These options are currently available:
namesβ list only locks with these names. Example:names => ['foo', 'bar']
These fields are currently available:
expiresβ epoch time this lock will expire. Example:expires => 784111777nameβ lock name. Example:name => 'foo'
π§ list_workers
my $results = $backend->list_workers($offset, $limit);
my $results = $backend->list_workers($offset, $limit, {ids => [23]});
Returns information about workers in batches. Worker check-in time, bestie. π―
# Get the total number of results (without limit)
my $num = $backend->list_workers(0, 100)->{total};
# Check worker host
my $results = $backend->list_workers(0, 1, {ids => [$worker_id]});
my $host = $results->{workers}[0]{host};
These options are currently available:
beforeβ list only workers before this id. Example:before => 23idsβ list only workers with these ids. Example:ids => ['23', '24']
These fields are currently available:
idβ worker id. Example:id => 22hostβ worker host. Example:host => 'localhost'jobsβ ids of jobs the worker is currently processing. Example:jobs => ['10023', '10024', '10025', '10029']notifiedβ epoch time worker sent the last heartbeat. Example:notified => 784111777pidβ process id of worker. Example:pid => 12345startedβ epoch time worker was started. Example:started => 784111777statusβ hash reference with whatever status information the worker would like to share. Example:status => {queues => ['default', 'important']}
π lock
my $bool = $backend->lock('foo', 3600);
my $bool = $backend->lock('foo', 3600, {limit => 20});
okay so this named-lock situation tries to acquire a lock that expires automatically after however many seconds you give it. An expiration time of 0 can be used to check if a named lock already exists without creating one. π
Options available rn:
limitβlimit => 20Number of shared locks with the same name that can be active at the same time, defaults to1.
note
my $bool = $backend->note($job_id, {mojo => 'rocks', minion => 'too'});
Change one or more metadata fields for a job. Setting a value to undef will remove the field. It is currently an error to attempt to set a metadata field with a name containing the characters ., [, or ]. π«Ά
receive
my $commands = $backend->receive($worker_id);
Receive remote control commands for worker.
register_worker
my $worker_id = $backend->register_worker;
my $worker_id = $backend->register_worker($worker_id);
my $worker_id = $backend->register_worker(
$worker_id, {status => {queues => ['default', 'important']}});
Register worker or send heartbeat to show that this worker is still alive. π
Options available rn:
statusβstatus => {queues => ['default', 'important']}Hash reference with whatever status information the worker would like to share.
remove_job
my $bool = $backend->remove_job($job_id);
Remove failed, finished or inactive job from queue. Bye bestie π
repair
$backend->repair;
Repair worker registry and job queue if necessary.
reset
$backend->reset({all => 1});
Reset job queue.
Options available rn:
allβall => 1Reset everything.locksβlocks => 1Reset only locks.
retry_job
my $bool = $backend->retry_job($job_id, $retries);
my $bool = $backend->retry_job($job_id, $retries, {delay => 10});
Transition job back to inactive state, already inactive jobs may also be retried to change options. π
Options available rn:
attemptsβattempts => 25Number of times performing this job will be attempted.delayβdelay => 10Delay job for this many seconds (from now).expireβexpire => 300Job is valid for this many seconds (from now) before it expires. Note that this option is EXPERIMENTAL and might change without warning!laxβlax => 1Existing jobs this job depends on may also have transitioned to thefailedstate to allow for it to be processed, defaults tofalse. Note that this option is EXPERIMENTAL and might change without warning!parentsβparents => [$id1, $id2, $id3]Jobs this job depends on.priorityβpriority => 5Job priority.queueβqueue => 'important'Queue to put job in.
stats
my $stats = $backend->stats;
Get statistics for the job queue.
These fields are currently available:
active_jobsβactive_jobs => 100Number of jobs inactivestate.active_locksβactive_locks => 100Number of active named locks.active_workersβactive_workers => 100Number of workers that are currently processing a job.delayed_jobsβdelayed_jobs => 100Number of jobs ininactivestate that are scheduled to run at specific time in the future.enqueued_jobsβenqueued_jobs => 100000Rough estimate of how many jobs have ever been enqueued.failed_jobsβfailed_jobs => 100Number of jobs infailedstate.finished_jobsβfinished_jobs => 100Number of jobs infinishedstate.inactive_jobsβinactive_jobs => 100Number of jobs ininactivestate.inactive_workersβinactive_workers => 100Number of workers that are currently not processing a job.uptimeβuptime => undefUptime in seconds. Always undefined for SQLite.workersβworkers => 200;Number of registered workers.
unlock
my $bool = $backend->unlock('foo');
Release a named lock. Freedom! π¦
unregister_worker
$backend->unregister_worker($worker_id);
Unregister worker.
π BUGS π
Report any issues on the public bugtracker. fr fr, they wanna know π
π AUTHOR π
Dan Book <dbook@cpan.org>
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2015 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
π¦ SEE ALSO π¦
Minion, Mojo::SQLite
cute little sign-off: this page is serving perl v5.42.0 energy, dated 2022-08-14, and itβs literally Minion...:SQLite(3pm) β mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Minion-Backend-SQLite 5.0.7-bp160.1.4 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms