NAME

Proc::JobQueue::Job - The $job objects for Proc::JobQueue

SYNOPSIS

 $job = Proc::JobQueue::Job->new(%params)

 $job->can_command()

 $job->can_callback()

 $job->start()

 $job->host($host)
 $job->host()

 $job->jobnum($jobnum)
 $job->jobnum()

 $job->queue($queue)
 $job->queue()

 $job->runnable()

 $job->finished()

 $job->success()

 $job->addpostcb()

DESCRIPTION

This is the base class for the $job objects used by This class is designed to be overloaded. For user APIs, see the "SEE ALSO" section.

CONSTRUCTION

The parameters for new() are:

desc

Sets a description for this job.

priority (default: 100)

Sets a priority for this job. Higher number is higher priority. Jobs with higher priorities will be run first.

queue

A Proc::JobQueue object, used for calling $queue->jobdone(). Usually set by Proc::JobQueue::startjob(). This can also be set by calling queue($queue).

jobnum

A job number. Usually set by Proc::JobQueue::startjob(). This can also be set by calling jobnum($jobnum).

host

The host this job will run on. Usually set by Proc::JobQueue::startjob(). This can also be set by calling jobnum($jobnum).

generate_command

A function callback to generate a unix command for this job.

callback

A function callback that is this job. The callback will be called when the job should run. The job will be passed as the argument to the callback.

 $job->callback($job).
on_failure

A function callback that will be invoked only if the job fails.

 $on_failure->($job, @exit_code)

METHODS

host, jobnum, queue

Get or set (if provided with a defined parameter) the host, jobnum, or queue parameter for the job.

checkjob

Checks to see if the job is still running. This only really works with jobs which are unix commands. If the job is done, checkjob() will invoke finished().

finished(@exit_code)

Called to signal that the job has completed. If $exit_code[0] is true, then the job is considered to have failed and failed() will be invoked. Otherwise, sucess() will be called. In either case the post callback (if any), $queue->jobdone and $queue->startmore will be invoked.

addpostcb($callback, @args)

Add a callback to be called when the job completes.

The $job object and the @exit_code will be added to the callback's arguments.

METHODS FOR SUBCLASSING

If you are subclassing Job then you may want to define these:

startup

If defined, then a call to this method is what is used to start the job running.

sucess()

Called when the job succeeds. Doesn't do anything -- it's a hook to override.

failed

Called when the job fails. Invokes the on_failure action if there is one.

runnable

Returns true if the job is runnable at this time.

checkjob

A return value of undef indicates the job is still running. A defined value is the exit code for the job.

start

Starts this job. This is usually called by Proc::JobQueue::startjob().

SEE ALSO

Proc::JobQueue Proc::JobQueue::DependencyJob Proc::JobQueue::RemoteDependencyJob Proc::JobQueue::Command Proc::JobQueue::Sort Proc::JobQueue::Move Proc::JobQueue::Sequence

LICENSE

Copyright (C) 2007-2008 SearchMe, Inc. Copyright (C) 2008-2010 David Sharnoff. Copyright (C) 2011 Google, Inc. This package may be used and redistributed under the terms of either the Artistic 2.0 or LGPL 2.1 license.