PHP Класс Resque_Worker, php-resque

Автор: Chris Boulton ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$logger Logging object that impliments the PSR-3 LoggerInterface

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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() публичный Метод

Generate a string representation of this worker.
public __toString ( ) : string
Результат string String identifier for this worker instance.

all() публичный статический Метод

Return all workers known to Resque as instantiated instances.
public static all ( ) : array
Результат array

doneWorking() публичный Метод

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

exists() публичный статический Метод

Given a worker ID, check if it is registered/valid.
public static exists ( string $workerId ) : boolean
$workerId string ID of the worker.
Результат boolean True if the worker exists, false if not.

find() публичный статический Метод

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.
Результат Resque_Worker Instance of the worker. False if the worker does not exist.

getStat() публичный Метод

Get a statistic belonging to this worker.
public getStat ( string $stat ) : integer
$stat string Statistic to fetch.
Результат integer Statistic value.

job() публичный Метод

Return an object describing the job this worker is currently working on.
public job ( ) : object
Результат object Object with details of current job.

killChild() публичный Метод

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

pauseProcessing() публичный Метод

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

perform() публичный Метод

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

pruneDeadWorkers() публичный Метод

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() публичный Метод

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.
Результат array Array of associated queues.

registerWorker() публичный Метод

Register this worker in Redis.
public registerWorker ( )

reserve() публичный Метод

public reserve ( boolean $blocking = false, integer $timeout = null ) : object | boolean
$blocking boolean
$timeout integer
Результат object | boolean Instance of Resque_Job if a job is found, false if not.

setId() публичный Метод

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

setLogger() публичный Метод

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

shutdown() публичный Метод

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() публичный Метод

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

unPauseProcessing() публичный Метод

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

unregisterWorker() публичный Метод

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

work() публичный Метод

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() публичный Метод

Return an array of process IDs for all of the Resque workers currently running on this machine.
public workerPids ( ) : array
Результат array Array of Resque worker process IDs.

workingOn() публичный Метод

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.

Описание свойств

$logger публичное свойство

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