TheSchwartz::Moosified - TheSchwartz based on Moose!


TheSchwartz-Moosified documentation  | view source Contained in the TheSchwartz-Moosified distribution.

Index


NAME

Top

TheSchwartz::Moosified - TheSchwartz based on Moose!

SYNOPSIS

Top

    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();

DESCRIPTION

Top

TheSchwartz is a powerful job queue. This module is a Moose implemention.

read more on TheSchwartz

SETTING

Top

* databases

An arrayref of dbh.

    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

control the debug.

    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";
    } );

* 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" );

POSTING JOBS

Top

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.

$client->insert( $funcname, $arg )

Adds a new job with funcname $funcname and arguments $arg to the queue.

WORKING

Top

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.

$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.

$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.

$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.

$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.

SEE ALSO

Top

TheSchwartz, TheSchwartz::Simple

AUTHOR

Top

Fayland Lam, <fayland at gmail.com>

Jeremy Stashewsky, <jstash+cpan at gmail.com>

COPYRIGHT & LICENSE

Top


TheSchwartz-Moosified documentation  | view source Contained in the TheSchwartz-Moosified distribution.