PHP Class Resque_Worker, php-resque

Author: Chris Boulton ([email protected])
Afficher le fichier Open project: chrisboulton/php-resque Class Usage Examples

Méthodes publiques

Свойство Type Description
$logger Logging object that impliments the PSR-3 LoggerInterface

Méthodes publiques

Méthode 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

Méthode 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 méthode

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 méthode

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

all() public static méthode

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

doneWorking() public méthode

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

exists() public static méthode

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

find() public static méthode

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.
Résultat Resque_Worker Instance of the worker. False if the worker does not exist.

getStat() public méthode

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

job() public méthode

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

killChild() public méthode

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

pauseProcessing() public méthode

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

perform() public méthode

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

pruneDeadWorkers() public méthode

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 méthode

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.
Résultat array Array of associated queues.

registerWorker() public méthode

Register this worker in Redis.
public registerWorker ( )

reserve() public méthode

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

setId() public méthode

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

setLogger() public méthode

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

shutdown() public méthode

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 méthode

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

unPauseProcessing() public méthode

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

unregisterWorker() public méthode

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

work() public méthode

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 méthode

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

workingOn() public méthode

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