PHP Class Resque_Worker, php-resque

Author: Chris Boulton ([email protected])
ファイルを表示 Open project: chrisboulton/php-resque Class Usage Examples

Public Properties

Property Type Description
$logger Logging object that impliments the PSR-3 LoggerInterface

Public Methods

Method Description
__construct ( string | array $queues ) Instantiate a new worker, given a list of queues that it should be working on. The list of queues should be supplied in the priority that they should be checked for jobs (first come, first served)
__toString ( ) : string Generate a string representation of this worker.
all ( ) : array Return all workers known to Resque as instantiated instances.
doneWorking ( ) Notify Redis that we've finished working on a job, clearing the working state and incrementing the job stats.
exists ( string $workerId ) : boolean Given a worker ID, check if it is registered/valid.
find ( string $workerId ) : Resque_Worker Given a worker ID, find it and return an instantiated worker class for it.
getStat ( string $stat ) : integer Get a statistic belonging to this worker.
job ( ) : object Return an object describing the job this worker is currently working on.
killChild ( ) Kill a forked child job immediately. The job it is processing will not be completed.
pauseProcessing ( ) Signal handler callback for USR2, pauses processing of new jobs.
perform ( Resque_Job $job ) Process a single job.
pruneDeadWorkers ( ) Look for any workers which should be running on this server and if they're not, remove them from Redis.
queues ( boolean $fetch = true ) : array Return an array containing all of the queues that this worker should use when searching for jobs.
registerWorker ( ) Register this worker in Redis.
reserve ( boolean $blocking = false, integer $timeout = null ) : object | boolean
setId ( string $workerId ) Set the ID of this worker to a given ID string.
setLogger ( Psr\Log\LoggerInterface $logger ) Inject the logging object into the worker
shutdown ( ) Schedule a worker for shutdown. Will finish processing the current job and when the timeout interval is reached, the worker will shut down.
shutdownNow ( ) Force an immediate shutdown of the worker, killing any child jobs currently running.
unPauseProcessing ( ) Signal handler callback for CONT, resumes worker allowing it to pick up new jobs.
unregisterWorker ( ) Unregister this worker in Redis. (shutdown etc)
work ( integer $interval = Resque::DEFAULT_INTERVAL, $blocking = false ) The primary loop for a worker which when called on an instance starts the worker's life cycle.
workerPids ( ) : array Return an array of process IDs for all of the Resque workers currently running on this machine.
workingOn ( Resque_Job $job ) Tell Redis which job we're currently working on.

Private Methods

Method Description
registerSigHandlers ( ) Register signal handlers that a worker should respond to.
startup ( ) Perform necessary actions to start a worker.
updateProcLine ( string $status ) On supported systems (with the PECL proctitle module installed), update the name of the currently running process to indicate the current state of a worker.

Method Details

__construct() public method

Passing a single '*' allows the worker to work on all queues in alphabetical order. You can easily add new queues dynamically and have them worked on using this method.
public __construct ( string | array $queues )
$queues string | array String with a single queue name, array with multiple.

__toString() public method

Generate a string representation of this worker.
public __toString ( ) : string
return string String identifier for this worker instance.

all() public static method

Return all workers known to Resque as instantiated instances.
public static all ( ) : array
return array

doneWorking() public method

Notify Redis that we've finished working on a job, clearing the working state and incrementing the job stats.
public doneWorking ( )

exists() public static method

Given a worker ID, check if it is registered/valid.
public static exists ( string $workerId ) : boolean
$workerId string ID of the worker.
return boolean True if the worker exists, false if not.

find() public static method

Given a worker ID, find it and return an instantiated worker class for it.
public static find ( string $workerId ) : Resque_Worker
$workerId string The ID of the worker.
return Resque_Worker Instance of the worker. False if the worker does not exist.

getStat() public method

Get a statistic belonging to this worker.
public getStat ( string $stat ) : integer
$stat string Statistic to fetch.
return integer Statistic value.

job() public method

Return an object describing the job this worker is currently working on.
public job ( ) : object
return object Object with details of current job.

killChild() public method

Kill a forked child job immediately. The job it is processing will not be completed.
public killChild ( )

pauseProcessing() public method

Signal handler callback for USR2, pauses processing of new jobs.
public pauseProcessing ( )

perform() public method

Process a single job.
public perform ( Resque_Job $job )
$job Resque_Job The job to be processed.

pruneDeadWorkers() public method

This is a form of garbage collection to handle cases where the server may have been killed and the Resque workers did not die gracefully and therefore leave state information in Redis.
public pruneDeadWorkers ( )

queues() public method

If * is found in the list of queues, every queue will be searched in alphabetic order. (@see $fetch)
public queues ( boolean $fetch = true ) : array
$fetch boolean If true, and the queue is set to *, will fetch all queue names from redis.
return array Array of associated queues.

registerWorker() public method

Register this worker in Redis.
public registerWorker ( )

reserve() public method

public reserve ( boolean $blocking = false, integer $timeout = null ) : object | boolean
$blocking boolean
$timeout integer
return object | boolean Instance of Resque_Job if a job is found, false if not.

setId() public method

Set the ID of this worker to a given ID string.
public setId ( string $workerId )
$workerId string ID for the worker.

setLogger() public method

Inject the logging object into the worker
public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface

shutdown() public method

Schedule a worker for shutdown. Will finish processing the current job and when the timeout interval is reached, the worker will shut down.
public shutdown ( )

shutdownNow() public method

Force an immediate shutdown of the worker, killing any child jobs currently running.
public shutdownNow ( )

unPauseProcessing() public method

Signal handler callback for CONT, resumes worker allowing it to pick up new jobs.
public unPauseProcessing ( )

unregisterWorker() public method

Unregister this worker in Redis. (shutdown etc)
public unregisterWorker ( )

work() public method

Queues are checked every $interval (seconds) for new jobs.
public work ( integer $interval = Resque::DEFAULT_INTERVAL, $blocking = false )
$interval integer How often to check for new jobs across the queues.

workerPids() public method

Return an array of process IDs for all of the Resque workers currently running on this machine.
public workerPids ( ) : array
return array Array of Resque worker process IDs.

workingOn() public method

Tell Redis which job we're currently working on.
public workingOn ( Resque_Job $job )
$job Resque_Job Resque_Job instance containing the job we're working on.

Property Details

$logger public_oe property

Logging object that impliments the PSR-3 LoggerInterface
public $logger