PHP Класс Resque\Worker

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

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

Свойство Тип Описание
$statusText Worker status constants as text

Защищенные свойства (Protected)

Свойство Тип Описание
$blocking True if uses Redis pop blocking
$child Process ID of child worker processes.
$host The host of this worker.
$id String identifying this worker.
$interval Clock speed
$job Current job, if any, being processed by this worker.
$logger logger instance
$memoryLimit Memory limit of worker, if exceeded worker will stop
$pid Process id of this worker
$pidFile File to store process id in
$queues Array of all associated queues for this worker.
$redis Redis The Redis instance.
$shutdown True if on the next iteration, the worker should shutdown.
$shutdownErrors List of shutdown errors to catch
$status Status of the worker.
$timeout Max execution time of job

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

Метод Описание
__construct ( mixed $queues = '*', boolean $blocking = true ) Create a new worker.
__toString ( ) : string Generate a string representation of this worker.
allWorkers ( Logger $logger = null ) : array Return all known workers
cancelJob ( ) Cancel the currently running job
cleanup ( ) Look for any workers which should be running on this server and if they're not, remove them from Redis.
doneWorking ( ) Notify Redis that we've finished working on a job, clearing the working state and incrementing the job stats.
forceShutdown ( ) Force an immediate shutdown of the worker, killing any child jobs currently running.
fromId ( string $id, Logger $logger = null ) : Worker Return a worker from it's ID
getBlocking ( ) : boolean Get the queue blocking.
getHost ( ) : Host Get the queue host.
getId ( ) : string Get the worker id.
getInterval ( ) : integer Get the worker interval.
getLogger ( ) : Logger Get the logger instance
getMemoryLimit ( ) : integer Get the queue memory limit.
getPacket ( ) : array | false Fetch the packet for the worker
getPid ( ) : integer Get the worker process id.
getPidFile ( ) : string Get the worker pid file.
getQueues ( ) : string Get the worker queues.
getTimeout ( ) : integer Get the worker queue timeout.
hostWorker ( string $id, string $host = null, Logger $logger = null ) : array | false Return host worker by id
hostWorkers ( string $host = null, Logger $logger = null ) : array Return all known workers
killChild ( ) Kill a forked child job immediately. The job it is processing will not be completed.
log ( ) : mixed Helper function that passes through to logger instance
perform ( Job $job ) Process a single job
queueDelayed ( integer $endTime = null, integer $startTime ) Find any delayed jobs and add them to the queue if found
redisKey ( Worker $worker = null, string $suffix = null ) : string Get the Redis key
register ( ) Register this worker in Redis and signal handlers that a worker should respond to
resolveQueues ( ) : array Return an array containing all of the queues that this worker should use when searching for jobs.
setBlocking ( boolean $blocking ) Set the queue blocking
setHost ( Host $host ) Set the queue host
setId ( string $id ) Set the worker id
setInterval ( integer $interval ) Set the worker interval
setLogger ( Logger $logger = null ) Set the logger instance
setMemoryLimit ( integer $memoryLimit ) Set the queue memory limit
setPid ( integer $pid ) Set the worker process id - this is done when worker is loaded from memory
setPidFile ( string $pidFile ) Set the worker pid file
setQueues ( string $queues ) : array Set the worker queues
setStatus ( integer $status ) Update the status indicator for the current worker with a new status.
setTimeout ( string $timeout ) : string Set the worker queue timeout
shutdown ( ) Schedule a worker for shutdown. Will finish processing the current job and when the timeout interval is reached, the worker will shut down.
sigCancelJob ( ) Signal handler callback for USR1, cancel current job.
sigForceShutdown ( integer $sig ) Signal handler callback for TERM or INT, forces shutdown of worker
sigPause ( ) Signal handler callback for USR2, pauses processing of new jobs.
sigResume ( ) Signal handler callback for CONT, resumes worker allowing it to pick up new jobs.
sigShutdown ( ) Signal handler callback for QUIT, shutdown the worker.
sigWakeUp ( ) Signal handler for SIGPIPE, in the event the Redis connection has gone away.
toArray ( ) : array Return array representation of this job
unregister ( ) Unregister this worker in Redis
work ( ) The primary loop for a worker which when called on an instance starts the worker's life cycle.
workingOn ( Job &$job ) Tell Redis which job we're currently working on.

Защищенные методы

Метод Описание
getProcessTitle ( $status ) Creates process title string from current version and status of worker
interval_string ( ) : string Returns formatted interval string
memoryExceeded ( ) : boolean Determine if the memory limit has been exceeded.
startup ( ) Perform necessary actions to start a worker
updateProcLine ( string $status ) On supported systems, update the name of the currently running process to indicate the current state of a worker.

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

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

Create a new worker.
public __construct ( mixed $queues = '*', boolean $blocking = true )
$queues mixed Queues for the worker to watch
$blocking boolean Use Redis blocking

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

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

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

Return all known workers
public static allWorkers ( Logger $logger = null ) : array
$logger Logger
Результат array

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

Cancel the currently running job
public cancelJob ( )

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

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

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

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

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

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

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

Return a worker from it's ID
public static fromId ( string $id, Logger $logger = null ) : Worker
$id string Worker id
$logger Logger Logger for the worker to use
Результат Worker

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

Get the queue blocking.
public getBlocking ( ) : boolean
Результат boolean

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

Get the queue host.
public getHost ( ) : Host
Результат Host

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

Get the worker id.
public getId ( ) : string
Результат string

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

Get the worker interval.
public getInterval ( ) : integer
Результат integer

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

Get the logger instance
public getLogger ( ) : Logger
Результат Logger

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

Get the queue memory limit.
public getMemoryLimit ( ) : integer
Результат integer Memory limit

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

Fetch the packet for the worker
public getPacket ( ) : array | false
Результат array | false The worker packet or false

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

Get the worker process id.
public getPid ( ) : integer
Результат integer

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

Get the worker pid file.
public getPidFile ( ) : string
Результат string

getProcessTitle() защищенный Метод

Creates process title string from current version and status of worker
protected getProcessTitle ( $status )

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

Get the worker queues.
public getQueues ( ) : string
Результат string

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

Get the worker queue timeout.
public getTimeout ( ) : integer
Результат integer Worker queue timeout

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

Return host worker by id
public static hostWorker ( string $id, string $host = null, Logger $logger = null ) : array | false
$id string Worker id
$host string Hostname
$logger Logger Logger
Результат array | false

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

Return all known workers
public static hostWorkers ( string $host = null, Logger $logger = null ) : array
$host string Hostname
$logger Logger Logger
Результат array

interval_string() защищенный Метод

Returns formatted interval string
protected interval_string ( ) : string
Результат string

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

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

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

Helper function that passes through to logger instance
См. также: Logger::log For more documentation
public log ( ) : mixed
Результат mixed

memoryExceeded() защищенный Метод

Determine if the memory limit has been exceeded.
protected memoryExceeded ( ) : boolean
Результат boolean

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

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

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

Find any delayed jobs and add them to the queue if found
public queueDelayed ( integer $endTime = null, integer $startTime )
$endTime integer optional end time for range
$startTime integer optional start time for range

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

Get the Redis key
public static redisKey ( Worker $worker = null, string $suffix = null ) : string
$worker Worker the worker to get the key for
$suffix string to be appended to key
Результат string

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

- TERM: Shutdown immediately and stop processing jobs - INT: Shutdown immediately and stop processing jobs - QUIT: Shutdown after the current job finishes processing - USR1: Kill the forked child immediately and continue processing jobs
public register ( )

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

If * is found in the list of queues, every queue will be searched in alphabetic order.
public resolveQueues ( ) : array
Результат array Array of associated queues.

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

Set the queue blocking
public setBlocking ( boolean $blocking )
$blocking boolean Should worker use Redis blocking

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

Set the queue host
public setHost ( Host $host )
$host Host The host to set for this worker

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

Set the worker id
public setId ( string $id )
$id string Id to set to

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

Set the worker interval
public setInterval ( integer $interval )
$interval integer The worker interval

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

Set the logger instance
public setLogger ( Logger $logger = null )
$logger Logger The logger for this worker

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

Set the queue memory limit
public setMemoryLimit ( integer $memoryLimit )
$memoryLimit integer Memory limit

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

Set the worker process id - this is done when worker is loaded from memory
public setPid ( integer $pid )
$pid integer Set worker pid

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

Set the worker pid file
public setPidFile ( string $pidFile )
$pidFile string Filename to store pid in

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

Set the worker queues
public setQueues ( string $queues ) : array
$queues string Queues for worker to watch
Результат array

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

Update the status indicator for the current worker with a new status.
public setStatus ( integer $status )
$status integer The status of the worker

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

Set the worker queue timeout
public setTimeout ( string $timeout ) : string
$timeout string Worker queue timeout
Результат string

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 ( )

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

Signal handler callback for USR1, cancel current job.
public sigCancelJob ( )

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

Signal handler callback for TERM or INT, forces shutdown of worker
public sigForceShutdown ( integer $sig )
$sig integer Signal that was sent

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

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

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

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

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

Signal handler callback for QUIT, shutdown the worker.
public sigShutdown ( )

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

Attempts to reconnect to Redis, or raises an Exception.
public sigWakeUp ( )

startup() защищенный Метод

Perform necessary actions to start a worker
protected startup ( )

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

Return array representation of this job
public toArray ( ) : array
Результат array

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

Unregister this worker in Redis
public unregister ( )

updateProcLine() защищенный Метод

supported systems are - PHP Version < 5.5.0 with the PECL proctitle module installed - PHP Version >= 5.5.0 using built in method
protected updateProcLine ( string $status )
$status string The updated process title.

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

Queues are checked every $interval (seconds) for new jobs.
public work ( )

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

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

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

$blocking защищенное свойство

True if uses Redis pop blocking
protected $blocking

$child защищенное свойство

Process ID of child worker processes.
protected $child

$host защищенное свойство

The host of this worker.
protected $host

$id защищенное свойство

String identifying this worker.
protected $id

$interval защищенное свойство

Clock speed
protected $interval

$job защищенное свойство

Current job, if any, being processed by this worker.
protected $job

$logger защищенное свойство

logger instance
protected $logger

$memoryLimit защищенное свойство

Memory limit of worker, if exceeded worker will stop
protected $memoryLimit

$pid защищенное свойство

Process id of this worker
protected $pid

$pidFile защищенное свойство

File to store process id in
protected $pidFile

$queues защищенное свойство

Array of all associated queues for this worker.
protected $queues

$redis защищенное свойство

The Redis instance.
protected Redis,resque $redis
Результат Redis

$shutdown защищенное свойство

True if on the next iteration, the worker should shutdown.
protected $shutdown

$shutdownErrors защищенное свойство

List of shutdown errors to catch
protected $shutdownErrors

$status защищенное свойство

Status of the worker.
protected $status

$statusText публичное статическое свойство

Worker status constants as text
public static $statusText

$timeout защищенное свойство

Max execution time of job
protected $timeout