Jeremy Stashewsky > TheSchwartz-Moosified > TheSchwartz::Moosified

Download:
TheSchwartz-Moosified-0.06.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  3
View/Report Bugs
Module Version: 0.06   Source  

NAME ^

TheSchwartz::Moosified - TheSchwartz based on Moose!

SYNOPSIS ^

    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 ^

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

read more on TheSchwartz

SETTING ^

POSTING JOBS ^

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 ^

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 ^

TheSchwartz, TheSchwartz::Simple

AUTHOR ^

Fayland Lam, <fayland at gmail.com>

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

COPYRIGHT & LICENSE ^

Copyright 2008 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.

syntax highlighting: