Merge branch 'master' of git://github.com/chrisboulton/php-resque

This commit is contained in:
humancopy 2011-10-23 09:47:33 +02:00
commit 599295ef9c
8 changed files with 34 additions and 10 deletions

View file

@ -49,6 +49,10 @@ class Redisent {
function __construct($host, $port = 6379) {
$this->host = $host;
$this->port = $port;
$this->establishConnection();
}
function establishConnection() {
$this->__sock = fsockopen($this->host, $this->port, $errno, $errstr);
if (!$this->__sock) {
throw new Exception("{$errno} - {$errstr}");

View file

@ -26,7 +26,7 @@ class Resque
* @param mixed $server Host/port combination separated by a colon, or
* a nested array of servers with host/port pairs.
*/
public static function setBackend($server)
public static function setBackend($server, $database = 0)
{
if(is_array($server)) {
require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
@ -37,6 +37,8 @@ class Resque
require_once dirname(__FILE__) . '/Resque/Redis.php';
self::$redis = new Resque_Redis($host, $port);
}
self::redis()->select($database);
}
/**

View file

@ -63,7 +63,7 @@ class Resque_Job
$id = md5(uniqid('', true));
Resque::push($queue, array(
'class' => $class,
'args' => $args,
'args' => array($args),
'id' => $id,
));
@ -128,7 +128,7 @@ class Resque_Job
return array();
}
return $this->payload['args'];
return $this->payload['args'][0];
}
/**
@ -248,4 +248,4 @@ class Resque_Job
return '(' . implode(' | ', $name) . ')';
}
}
?>
?>

View file

@ -358,6 +358,7 @@ class Resque_Worker
pcntl_signal(SIGUSR1, array($this, 'killChild'));
pcntl_signal(SIGUSR2, array($this, 'pauseProcessing'));
pcntl_signal(SIGCONT, array($this, 'unPauseProcessing'));
pcntl_signal(SIGPIPE, array($this, 'reestablishRedisConnection'));
$this->log('Registered signals', self::LOG_VERBOSE);
}
@ -380,6 +381,16 @@ class Resque_Worker
$this->paused = false;
}
/**
* Signal handler for SIGPIPE, in the event the redis connection has gone away.
* Attempts to reconnect to redis, or raises an Exception.
*/
public function reestablishRedisConnection()
{
$this->log('SIGPIPE received; attempting to reconnect');
Resque::redis()->establishConnection();
}
/**
* Schedule a worker for shutdown. Will finish processing the current job
* and when the timeout interval is reached, the worker will shut down.