mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-22 00:11:53 +00:00
Merge pull request #299 from chrisboulton/fork-return
Return false if the fork function is unavailable
This commit is contained in:
commit
c928347ae7
@ -96,7 +96,7 @@ if(!empty($PREFIX)) {
|
|||||||
if($count > 1) {
|
if($count > 1) {
|
||||||
for($i = 0; $i < $count; ++$i) {
|
for($i = 0; $i < $count; ++$i) {
|
||||||
$pid = Resque::fork();
|
$pid = Resque::fork();
|
||||||
if($pid == -1) {
|
if($pid === false || pid === -1) {
|
||||||
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
|
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ class Resque
|
|||||||
*
|
*
|
||||||
* Will close connection to Redis before forking.
|
* Will close connection to Redis before forking.
|
||||||
*
|
*
|
||||||
* @return int Return vars as per pcntl_fork()
|
* @return int Return vars as per pcntl_fork(). False if pcntl_fork is unavailable
|
||||||
*/
|
*/
|
||||||
public static function fork()
|
public static function fork()
|
||||||
{
|
{
|
||||||
if(!function_exists('pcntl_fork')) {
|
if(!function_exists('pcntl_fork')) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the connection to Redis before forking.
|
// Close the connection to Redis before forking.
|
||||||
@ -281,12 +281,12 @@ class Resque
|
|||||||
$originalQueue = 'queue:'. $queue;
|
$originalQueue = 'queue:'. $queue;
|
||||||
$tempQueue = $originalQueue. ':temp:'. time();
|
$tempQueue = $originalQueue. ':temp:'. time();
|
||||||
$requeueQueue = $tempQueue. ':requeue';
|
$requeueQueue = $tempQueue. ':requeue';
|
||||||
|
|
||||||
// move each item from original queue to temp queue and process it
|
// move each item from original queue to temp queue and process it
|
||||||
$finished = false;
|
$finished = false;
|
||||||
while (!$finished) {
|
while (!$finished) {
|
||||||
$string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue);
|
$string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue);
|
||||||
|
|
||||||
if (!empty($string)) {
|
if (!empty($string)) {
|
||||||
if(self::matchItem($string, $items)) {
|
if(self::matchItem($string, $items)) {
|
||||||
self::redis()->rpop($tempQueue);
|
self::redis()->rpop($tempQueue);
|
||||||
@ -311,7 +311,7 @@ class Resque
|
|||||||
// remove temp queue and requeue queue
|
// remove temp queue and requeue queue
|
||||||
self::redis()->del($requeueQueue);
|
self::redis()->del($requeueQueue);
|
||||||
self::redis()->del($tempQueue);
|
self::redis()->del($tempQueue);
|
||||||
|
|
||||||
return $counter;
|
return $counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,4 +377,3 @@ class Resque
|
|||||||
return md5(uniqid('', true));
|
return md5(uniqid('', true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user