NAME

Gearman::Driver::Job - Handles the POE magic

DESCRIPTION

This class is responsible for starting/stopping processes as well as handling all pipes (STDOUT/STDERR/STDIN) of the processes. All events are written to a logfile. Possible events are:

  • Starting processes

  • STDOUT of processes

  • STDERR of processes

  • Stopping processes

The current interface may only be interesting for people subclassing Gearman::Driver or for people writing commands/extensions for Gearman::Driver::Console.

ATTRIBUTES

driver

Reference to the Gearman::Driver instance.

name

The job's name.

method

Code reference which is run called by Gearman::XS::Worker. Actually it's not called directly by it, but in a wrapped coderef.

worker

Reference to the worker object.

server

A list of Gearman servers the workers should connect to. The format for the server list is: host[:port][,host[:port]]

It's the same value as in "server" in Gearman::Driver.

max_processes

Maximum number of concurrent processes this job may have.

min_processes

Minimum number of concurrent processes this job may have.

encode

This may be set to a method name which is implemented in the worker class or any subclass. If the method is not available, it will fail. The returned value of the job method is passed to this method and the return value of this method is sent back to the Gearman server.

See also: "Encode" in Gearman::Driver::Worker.

decode

This may be set to a method name which is implemented in the worker class or any subclass. If the method is not available, it will fail. The workload from Gearman::XS::Job is passed to this method and the return value is passed as argument $workload to the job method.

See also: "Decode" in Gearman::Driver::Worker.

processes

This attribute stores a key/value pair containing: $pid => $job

It provides following methods:

  • count_processes()

  • delete_process($pid)

  • get_process($pid)

  • get_processes()

  • get_pids()

  • set_process($pid = $job)>

gearman

Instance of Gearman::XS::Worker.

session

Instance of POE::Session.

cache

An instance of Cache::FastMmap is used to share data between the parent and child processes. This is necessary to set lastrun, lasterror and lasterror_msg in the child processes and make the values available in the parent process.

lastrun

Each time this job is called it stores time() in this attribute as well was in the "cache".

lasterror

Each time this job failed it stores time() in this attribute as well was in the "cache".

lasterror_msg

Each time this job failed it stores the error message in this attribute as well was in the "cache".

METHODS

get_lastrun

Getter for "lastrun" which uses the "cache".

get_lasterror

Getter for "lasterror" which uses the "cache".

get_lasterror_msg

Getter for "lasterror_msg" which uses the "cache".

add_process

Starts/forks/adds another process of this job.

remove_process

Removes/kills one process of this job.

AUTHOR

See Gearman::Driver.

COPYRIGHT AND LICENSE

See Gearman::Driver.

SEE ALSO