Skip to content

Commit 599295e

Browse files
committed
Merge branch 'master' of git://github.com/chrisboulton/php-resque
2 parents cd3b0cc + 4c02511 commit 599295e

File tree

8 files changed

+34
-10
lines changed

8 files changed

+34
-10
lines changed

CHANGELOG.markdown

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
## 1.1 (2011-02-26) ##
1+
## 1.2 (Unreleased) ##
2+
3+
* Allow alternate redis database to be selected when calling setBackend by supplying a second argument (patrickbajao)
4+
* Use `require_once` when including php-resque after the app has been included in the sample resque.php to prevent include conflicts (andrewjshults)
5+
* Wrap job arguments in an array to improve compatibility with ruby resque (warezthebeef)
6+
* Fix a bug where the worker would spin out of control taking the server with it, if the redis connection was interrupted even briefly. Use SIGPIPE to trap this scenario cleanly. (d11wtq)
7+
8+
## 1.1 (2011-03-27) ##
29

310
* Update Redisent library for Redis 2.2 compatibility. Redis 2.2 is now required. (thedotedge)
411
* Trim output of `ps` to remove any prepended whitespace (KevBurnsJr)

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Jobs are queued as follows:
4747
require_once 'lib/Resque.php';
4848

4949
// Required if redis is located elsewhere
50-
Resque::setBackend('localhost', 6379);
50+
Resque::setBackend('localhost:6379');
5151

5252
$args = array(
5353
'name' => 'Chris'

lib/Redisent/Redisent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class Redisent {
4949
function __construct($host, $port = 6379) {
5050
$this->host = $host;
5151
$this->port = $port;
52+
$this->establishConnection();
53+
}
54+
55+
function establishConnection() {
5256
$this->__sock = fsockopen($this->host, $this->port, $errno, $errstr);
5357
if (!$this->__sock) {
5458
throw new Exception("{$errno} - {$errstr}");

lib/Resque.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Resque
2626
* @param mixed $server Host/port combination separated by a colon, or
2727
* a nested array of servers with host/port pairs.
2828
*/
29-
public static function setBackend($server)
29+
public static function setBackend($server, $database = 0)
3030
{
3131
if(is_array($server)) {
3232
require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
@@ -37,6 +37,8 @@ public static function setBackend($server)
3737
require_once dirname(__FILE__) . '/Resque/Redis.php';
3838
self::$redis = new Resque_Redis($host, $port);
3939
}
40+
41+
self::redis()->select($database);
4042
}
4143

4244
/**

lib/Resque/Job.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function create($queue, $class, $args = null, $monitor = false)
6363
$id = md5(uniqid('', true));
6464
Resque::push($queue, array(
6565
'class' => $class,
66-
'args' => $args,
66+
'args' => array($args),
6767
'id' => $id,
6868
));
6969

@@ -128,7 +128,7 @@ public function getArguments()
128128
return array();
129129
}
130130

131-
return $this->payload['args'];
131+
return $this->payload['args'][0];
132132
}
133133

134134
/**
@@ -248,4 +248,4 @@ public function __toString()
248248
return '(' . implode(' | ', $name) . ')';
249249
}
250250
}
251-
?>
251+
?>

lib/Resque/Worker.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ private function registerSigHandlers()
358358
pcntl_signal(SIGUSR1, array($this, 'killChild'));
359359
pcntl_signal(SIGUSR2, array($this, 'pauseProcessing'));
360360
pcntl_signal(SIGCONT, array($this, 'unPauseProcessing'));
361+
pcntl_signal(SIGPIPE, array($this, 'reestablishRedisConnection'));
361362
$this->log('Registered signals', self::LOG_VERBOSE);
362363
}
363364

@@ -380,6 +381,16 @@ public function unPauseProcessing()
380381
$this->paused = false;
381382
}
382383

384+
/**
385+
* Signal handler for SIGPIPE, in the event the redis connection has gone away.
386+
* Attempts to reconnect to redis, or raises an Exception.
387+
*/
388+
public function reestablishRedisConnection()
389+
{
390+
$this->log('SIGPIPE received; attempting to reconnect');
391+
Resque::redis()->establishConnection();
392+
}
393+
383394
/**
384395
* Schedule a worker for shutdown. Will finish processing the current job
385396
* and when the timeout interval is reached, the worker will shut down.

resque.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
require_once $APP_INCLUDE;
1414
}
1515

16-
require 'lib/Resque.php';
17-
require 'lib/Resque/Worker.php';
16+
require_once 'lib/Resque.php';
17+
require_once 'lib/Resque/Worker.php';
1818

1919
$REDIS_BACKEND = getenv('REDIS_BACKEND');
2020
if(!empty($REDIS_BACKEND)) {

test/Resque/Tests/JobTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testQueuedJobReturnsExactSamePassedInArguments()
6565
Resque::enqueue('jobs', 'Test_Job', $args);
6666
$job = Resque_Job::reserve('jobs');
6767

68-
$this->assertEquals($args, $job->payload['args']);
68+
$this->assertEquals($args, $job->getArguments());
6969
}
7070

7171
public function testAfterJobIsReservedItIsRemoved()
@@ -97,7 +97,7 @@ public function testRecreatedJobMatchesExistingJob()
9797

9898
$newJob = Resque_Job::reserve('jobs');
9999
$this->assertEquals($job->payload['class'], $newJob->payload['class']);
100-
$this->assertEquals($job->payload['args'], $newJob->payload['args']);
100+
$this->assertEquals($job->payload['args'], $newJob->getArguments());
101101
}
102102

103103
public function testFailedJobExceptionsAreCaught()

0 commit comments

Comments
 (0)