PHP 클래스 Resque\Worker

저자: Michael Haynes ([email protected])
파일 보기 프로젝트 열기: mjphaynes/php-resque 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$statusText Worker status constants as text

보호된 프로퍼티들

프로퍼티 타입 설명
$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