PHP Class Resque, php-resque

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

Public Properties

Property Type Description
$redis Instance of Resque_Redis that talks to redis.

Protected Properties

Property Type Description
$redisDatabase ID of Redis database to select.
$redisServer Host/port conbination separated by a colon, or a nested array of server swith host/port pairs

Public Methods

Method Description
blpop ( array $queues, integer $timeout ) : null | array Pop an item off the end of the specified queues, using blocking list pop, decode it and return it.
dequeue ( string $queue, array $items = [] ) : integer Remove items of the specified queue
enqueue ( string $queue, string $class, array $args = null, boolean $trackStatus = false ) : string | boolean Create a new job and save it to the specified queue.
fork ( ) : integer fork() helper method for php-resque that handles issues PHP socket and phpredis have with passing around sockets between child/parent processes.
generateJobId ( ) * Generate an identifier to attach to a job for status tracking.
pop ( string $queue ) : array Pop an item off the end of the specified queue, decode it and return it.
push ( string $queue, array $item ) Push a job to the end of a specific queue. If the queue does not exist, then create it as well.
queues ( ) : array Get an array of all known queues.
redis ( ) : Resque_Redis Return an instance of the Resque_Redis class instantiated for Resque.
removeQueue ( string $queue ) : integer Remove specified queue
reserve ( string $queue ) : Resque_Job Reserve and return the next available job in the specified queue.
setBackend ( mixed $server, integer $database ) Given a host/port combination separated by a colon, set it as the redis server that Resque will talk to.
size ( string $queue ) : integer Return the size (number of pending jobs) of the specified queue.

Private Methods

Method Description
matchItem ( $string, $items ) : (bool) matching item item can be ['class'] or ['class' => 'id'] or ['class' => {:foo => 1, :bar => 2}]
removeItems ( string $queue, array $items = [] ) : integer Remove Items from the queue Safely moving each item to a temporary queue before processing it If the Job matches, counts otherwise puts it in a requeue_queue which at the end eventually be copied back into the original queue
removeList ( $queue ) : integer Remove List

Method Details

blpop() public static method

Pop an item off the end of the specified queues, using blocking list pop, decode it and return it.
public static blpop ( array $queues, integer $timeout ) : null | array
$queues array
$timeout integer
return null | array Decoded item from the queue.

dequeue() public static method

Remove items of the specified queue
public static dequeue ( string $queue, array $items = [] ) : integer
$queue string The name of the queue to fetch an item from.
$items array
return integer number of deleted items

enqueue() public static method

Create a new job and save it to the specified queue.
public static enqueue ( string $queue, string $class, array $args = null, boolean $trackStatus = false ) : string | boolean
$queue string The name of the queue to place the job in.
$class string The name of the class that contains the code to execute the job.
$args array Any optional arguments that should be passed when the job is executed.
$trackStatus boolean Set to true to be able to monitor the status of a job.
return string | boolean Job ID when the job was created, false if creation was cancelled due to beforeEnqueue

fork() public static method

Will close connection to Redis before forking.
public static fork ( ) : integer
return integer Return vars as per pcntl_fork(). False if pcntl_fork is unavailable

generateJobId() public static method

* Generate an identifier to attach to a job for status tracking.
public static generateJobId ( )

pop() public static method

Pop an item off the end of the specified queue, decode it and return it.
public static pop ( string $queue ) : array
$queue string The name of the queue to fetch an item from.
return array Decoded item from the queue.

push() public static method

Push a job to the end of a specific queue. If the queue does not exist, then create it as well.
public static push ( string $queue, array $item )
$queue string The name of the queue to add the job to.
$item array Job description as an array to be JSON encoded.

queues() public static method

Get an array of all known queues.
public static queues ( ) : array
return array Array of queues.

redis() public static method

Return an instance of the Resque_Redis class instantiated for Resque.
public static redis ( ) : Resque_Redis
return Resque_Redis Instance of Resque_Redis.

removeQueue() public static method

Remove specified queue
public static removeQueue ( string $queue ) : integer
$queue string The name of the queue to remove.
return integer Number of deleted items

reserve() public static method

Reserve and return the next available job in the specified queue.
public static reserve ( string $queue ) : Resque_Job
$queue string Queue to fetch next available job from.
return Resque_Job Instance of Resque_Job to be processed, false if none or error.

setBackend() public static method

Given a host/port combination separated by a colon, set it as the redis server that Resque will talk to.
public static setBackend ( mixed $server, integer $database )
$server mixed Host/port combination separated by a colon, DSN-formatted URI, or a callable that receives the configured database ID and returns a Resque_Redis instance, or a nested array of servers with host/port pairs.
$database integer

size() public static method

Return the size (number of pending jobs) of the specified queue.
public static size ( string $queue ) : integer
$queue string name of the queue to be checked for pending jobs
return integer The size of the queue.

Property Details

$redis public_oe static_oe property

Instance of Resque_Redis that talks to redis.
public static $redis

$redisDatabase protected_oe static_oe property

ID of Redis database to select.
protected static $redisDatabase

$redisServer protected_oe static_oe property

Host/port conbination separated by a colon, or a nested array of server swith host/port pairs
protected static $redisServer