Author image Alan Kasindorf
and 1 contributors


Garivini::Client - Thin client for submitting jobs via Garivini


    use Garivini::Client;

    # Client
    my $cli = Garivini::Client->new(dbs => {
        1 => { id => 1, dsn => 'DBI:mysql:job:host=', user => 'job',
            pass => 'job' } });
    $cli->insert_job(funcname => 'hello', arg => 'world');

    # Worker
    use Gearman::Worker;
    use JSON;

    my $cli = Garivini::Client->new(dbs => {
        1 => { id => 1, dsn => 'DBI:mysql:job:host=', user => 'job',
            pass => 'job' } });
    my $worker = Gearman::Worker->new;
    $worker->register_function('hello' => \&hello);

    sub hello {
        my $job = decode_json(${$_[0]->argref});
        print "Hello ", $job->{arg}, "\n";


Client used for issuing and removing jobs directly from a Garivini database. Used by client code directly, or indirectly via the supplied workers.


    $cli = Garivini::Client->new( %OPTIONS );

Creates a new client object. The only arguments it takes are for initializing a Garivini::DB object.


Takes a hash of arguments and directly tosses a job into the a DB.


Hash describing a job


worker function name to execute the job


if given, offset from now for when to run job


only run one job with this id (per database defined!)


unimplemented. for running similar jobs together


serialized blob payload.


Optional; if set to 'shim', indicates that the job will be completed by a worker directly using Garivini::Client. If set to 'controller', the system will expect an Garivini::Controller worker to manage completion of the job.

    $cli->insert_jobs($jobs, $in, $flag);

Takes an array of arrays as jobs.

Jobs are defined as an array of arrays, in order: ['funcname', 'uniqkey', 'coalesce', 'arg']

Optionally $in is used for delaying job execution. All jobs will use the same value.

Optionally $flag is defined, as noted in "insert_jobs" above. All jobs will use the same value.

There is presently no way to do low latency submission for mass jobs, however they may still be executed via controller workers afterwards.


Takes a job handle and removes the job from the database. Job handles are received by Gearman workers, with the dbid and jobid's filled in.

    $cli->reschedule_job($job_handle, $when);

Reschedules a job for some time in the future, in case of temporary failure. You should call "failed_job" instead of this in most cases.


When to reschedule the job.

"never" sets the job to execute in 2038, long after civilization has been reclaimed. This leaves the job in the database for inspection, but will avoid retrying it.

"+360" would retry the job again in six minutes from now.

"1313572984" would retry the job at a specific unix timestamp.


Reschedules a job to retry in the future in case of a temporary failure. Applies a generic backoff algorithm based on the number of times the job has failed. Starts at two minutes and caps at one day.