NAME
Daemonise::Plugin::JobQueue - Daemonise JobQueue plugin
VERSION
version 2.13
SYNOPSIS
use Daemonise;
my $d = Daemonise->new();
$d->debug(1);
$d->foreground(1) if $d->debug;
$d->config_file('/path/to/some.conf');
$d->load_plugin('JobQueue');
$d->configure;
# fetch job from "jobqueue_db" and put it in $d->job
my $job_id = '585675aab87f878c9e98779e9e9c9ccadff';
my $job = $d->get_job($job_id);
# creates a new job in "jobqueue_db"
$job = $d->create_job({ some => { structured => 'hash' } });
# starts new job by sending a new job message to workflow worker
$d->start_job('workflow_name', { user => "kevin", command => "play" });
# searches for job in couchdb using view 'find/by_something' and key provided
$job = $d->find_job('by_bottles', "bottle_id");
# if you REALLY have to persist something in jobqueue right now, rather don't
$d->update_job($d->job->{message} || $job->{message});
# mark job as done and persist
$d->job_done($d->job->{message});
# stops workflow here if it is a job (if it has a message->meta->job_id)
$d->stop_here;
# recalculate totals
$d->recalculate;
# remove items from a job
$d->remove_items($d->job->{message}->{data}->{options}, qw(item1 item2 item3));
ATTRIBUTES
jobqueue_db
job
items_key
item_key
log_worker_enabled
job_locked
jobqueue_sync_delay
SUBROUTINES/METHODS provided
configure
log
log additional meta info of a job if present. this adds job
(from <meta-
id>>, session
, user
, account
from the meta
hash in front of each log message for easy tracking in any kind of log analyzer later.
start
stop
unlock job before we get terminated
queue
pass on some meta information if needed (user, account, session). unlock job ID before sending it off unless it's already unlocked or locking failed.
dequeue
store rabbitMQ message in job attribute after receiving. try to lock job ID if applicable
ack
empty job attribute before acknowledging a rabbitMQ message
hooks
method wrapper around _hooks attribute to accept hashes instead of a hash reference for convenience.
_finish_processing
this method exists to collect all common tasks needed to finish up a message
1. log error if exists 2. log wait_for key if job stops here 3. log worker & update job unless locking failed (job only) 4. unlock job (job only) 5. reply to calling worker/rabbit if needed 6. acknowledge AMQP message
lock_job
if message is a job, (un)lock rabbit on it using "activejob:job_id" as key and "some.rabbit.name:PID" as lock value.
if locking fails, throws error and returns undef, otherwise returns true.
unlock_job
call lock_job in 'unlock' mode and set boolean attribute
dont_log_worker
disable worker logging in msg->meta->log array
get_job
create_job
start_job
update_job
job_done
job_failed
job_pending
log_worker
find_job
find_all_jobs
stop_here
recalculate
find_item_index
Find the index of a particular item name in the $data-
{items_key}> array.
Return undef if not found.
remove_items
Given a list of item names to remove, remove them from $data-
{$self->items_key}> array and save them in $data-
{'removed_' . $self->items_key}> array.
If item isn't found, it is silently ignored.
Return value is an array of removed item hashes.
AUTHOR
Lenz Gschwendtner <norbu09@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Lenz Gschwendtner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.