TheSchwartz::Moosified - TheSchwartz based on Moose!
use TheSchwartz::Moosified; my $client = TheSchwartz::Moosified->new(); $client->databases([$dbh]); # rest are the same as TheSchwartz # in some place we insert job into TheSchwartz::Moosified # in another place we run this job # 1, insert job in cgi/Catalyst use TheSchwartz::Moosified; my $client = TheSchwartz::Moosified->new(); $client->databases([$dbh]); $client->insert('My::Worker::A', { args1 => 1, args2 => 2 } ); # 2, defined the heavy things in My::Worker::A package My::Worker::A; use base 'TheSchwartz::Moosified::Worker'; sub work { my ($class, $job) = @_; # $job is an instance of TheSchwartz::Moosified::Job my $args = $job->args; # do heavy things like resize photos, add 1 to 2 etc. $job->completed; } # 3, run the worker in a non-stop script use TheSchwartz::Moosified; my $client = TheSchwartz::Moosified->new(); $client->databases([$dbh]); $client->can_do('My::Worker::A'); $client->work();
TheSchwartz is a powerful job queue. This module is a Moose implemention.
read more on TheSchwartz
databases
Databases containing TheSchwartz jobs, shuffled before each use.
my $dbh1 = DBI->conncet(@dbi_info); my $dbh2 = $schema->storage->dbh; my $client = TheSchwartz::Moosified->new( databases => [ $dbh1, $dbh2 ] ); # or my $client = TheSchwartz::Moosified->new(); $client->databases( [ $dbh1, $dbh2 ] );
verbose
controls debug logging.
my $client = TheSchwartz::Moosified->new( verbose => 1 ); # or my $client = TheSchwartz::Moosified->new(); $client->verbose( 1 ); $client->verbose( sub { my $msg = shift; print STDERR "[INFO] $msg\n"; } );
prefix
optional prefix for tables. compatible with TheSchwartz::Simple
my $client = TheSchwartz::Moosified->new( prefix => 'theschwartz_' );
scoreboard
save job info to file. by default, the file will be saved at $tmpdir/theschwartz/scoreboard.$$
my $client = TheSchwartz::Moosified->new( scoreboard => 1 ); # or my $client = TheSchwartz::Moosified->new(); # be sure the file is there $client->scoreboard( "/home/fayland/theschwartz/scoreboard.log" );
error_length
optional, defaults to 255. Messages logged to the failure_log (the error table) are truncated to this length. Setting this to zero means no truncation (although the database you are using may truncate this for you).
failure_log
error
The methods of TheSchwartz clients used by applications posting jobs to the queue are:
$client->insert( $job )
Adds the given TheSchwartz::Job to one of the client's job databases.
TheSchwartz::Job
$client->insert( $funcname, $arg )
Adds a new job with funcname $funcname and arguments $arg to the queue.
$funcname
$arg
The methods of TheSchwartz clients for use in worker processes are:
$client->can_do( $ability )
Adds $ability to the list of abilities $client is capable of performing. Subsequent calls to that client's work methods will find jobs requiring the given ability.
$ability
$client
work
$client->work_once()
Find and perform one job $client can do.
$client->work_until_done()
Find and perform jobs $client can do until no more such jobs are found in any of the client's job databases.
$client->work( [$delay] )
Find and perform any jobs $client can do, forever. When no job is available, the working process will sleep for $delay seconds (or 5, if not specified) before looking again.
$delay
$client->find_job_for_workers( [$abilities] )
Returns a TheSchwartz::Job for a random job that the client can do. If specified, the job returned matches one of the abilities in the arrayref $abilities, rather than $client's abilities.
$abilities
$client->find_job_with_coalescing_value( $ability, $coval )
Returns a TheSchwartz::Job for a random job for a worker capable of $ability and with a coalescing value of $coval.
$coval
$client->find_job_with_coalescing_prefix( $ability, $coval )
Returns a TheSchwartz::Job for a random job for a worker capable of $ability and with a coalescing value beginning with $coval.
Note the TheSchwartz implementation of this function uses a LIKE query to find matching jobs, with all the attendant performance implications for your job databases.
TheSchwartz
LIKE
TheSchwartz, TheSchwartz::Simple
Fayland Lam, <fayland at gmail.com>
<fayland at gmail.com>
Jeremy Stashewsky, <jstash+cpan at gmail.com>
<jstash+cpan at gmail.com>
Luke Closs <cpan at 5thplane.com>
<cpan at 5thplane.com>
Copyright 2008,2016 Fayland Lam, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install TheSchwartz::Moosified, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TheSchwartz::Moosified
CPAN shell
perl -MCPAN -e shell install TheSchwartz::Moosified
For more information on module installation, please visit the detailed CPAN module installation guide.