From ea441e7e8deb905a4bffce21a5d9881035f2355c Mon Sep 17 00:00:00 2001 From: "chris.boulton" Date: Sun, 27 Mar 2011 19:19:30 +1100 Subject: [PATCH 01/13] Update release date for 1.1 --- CHANGELOG.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 38e57da..a4b2af2 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,4 +1,4 @@ -## 1.1 (2011-02-26) ## +## 1.1 (2011-03-27) ## * Update Redisent library for Redis 2.2 compatibility. Redis 2.2 is now required. (thedotedge) * Trim output of `ps` to remove any prepended whitespace (KevBurnsJr) From 91c6fff601a4915c260c72888929e76a2976f70d Mon Sep 17 00:00:00 2001 From: Josh Hawthorne Date: Thu, 14 Apr 2011 19:43:04 -0500 Subject: [PATCH 02/13] updated readme example of how to setBackend to use a single param with a colon for server:port rather than two separate variables --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index ab490bd..7066213 100644 --- a/README.markdown +++ b/README.markdown @@ -47,7 +47,7 @@ Jobs are queued as follows: require_once 'lib/Resque.php'; // Required if redis is located elsewhere - Resque::setBackend('localhost', 6379); + Resque::setBackend('localhost:6379'); $args = array( 'name' => 'Chris' From 1a5564ded506b1c859f0c15ef22f5f6d79782eb7 Mon Sep 17 00:00:00 2001 From: Andrew Shults Date: Wed, 8 Jun 2011 20:37:54 -0400 Subject: [PATCH 03/13] Switch to using require_once since it seems there are some conflicts with the autoloader --- resque.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resque.php b/resque.php index d020622..d85a70e 100644 --- a/resque.php +++ b/resque.php @@ -13,8 +13,8 @@ if($APP_INCLUDE) { require_once $APP_INCLUDE; } -require 'lib/Resque.php'; -require 'lib/Resque/Worker.php'; +require_once 'lib/Resque.php'; +require_once 'lib/Resque/Worker.php'; $REDIS_BACKEND = getenv('REDIS_BACKEND'); if(!empty($REDIS_BACKEND)) { From 96e2b21ef7bfa810d5da2cac86019b041ded8193 Mon Sep 17 00:00:00 2001 From: "chris.boulton" Date: Tue, 14 Jun 2011 19:29:43 +1000 Subject: [PATCH 04/13] Update changelog to mention bug fix by andrewjshults --- CHANGELOG.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index a4b2af2..97a9581 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,7 @@ +## 1.2 (Unreleased) ## + +* Use `require_once` when including php-resque after the app has been included in the sample resque.php to prevent include conflicts (andrewjshults) + ## 1.1 (2011-03-27) ## * Update Redisent library for Redis 2.2 compatibility. Redis 2.2 is now required. (thedotedge) From 27beb8cc20a8a2ea1a69813c3bc08786d0f6e347 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 17 Jan 2011 00:44:17 +0800 Subject: [PATCH 05/13] Added database parameter in setBackend() to select the database for a connection. The default database is set to 0. --- lib/Resque.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Resque.php b/lib/Resque.php index 168d849..c28a889 100644 --- a/lib/Resque.php +++ b/lib/Resque.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); } /** From 863099564e401eee7552e2327b2889c049b2a211 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 17 Jan 2011 01:15:31 +0800 Subject: [PATCH 06/13] Modified setBackend() to accept as the second parameter --- lib/Resque.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Resque.php b/lib/Resque.php index c28a889..d429ae5 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -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'; From 2a73e5b3901e1a94195007ad06ac819bdcf2d3e2 Mon Sep 17 00:00:00 2001 From: "chris.boulton" Date: Tue, 14 Jun 2011 19:36:29 +1000 Subject: [PATCH 07/13] Update changelog to include details of patrickbajao's modifications to allow setBackend to accept a redis database to use as a second argument --- CHANGELOG.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 97a9581..ba4193d 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,5 +1,6 @@ ## 1.2 (Unreleased) ## +* Allow alternate redis database to be selected when calling setBackend by supplying a second argument (patrickbajao) * Use `require_once` when including php-resque after the app has been included in the sample resque.php to prevent include conflicts (andrewjshults) ## 1.1 (2011-03-27) ## From f7eac3b5e7696c0f7c78750a2b9a5f63d4102e48 Mon Sep 17 00:00:00 2001 From: warezthebeef Date: Thu, 21 Jul 2011 15:49:18 +1200 Subject: [PATCH 08/13] Added wrapping array() to args to improve compatibility with ruby resque --- lib/Resque/Job.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 9d674f5..c820412 100644 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -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 array_shift($this->payload['args']); } /** @@ -248,4 +248,4 @@ class Resque_Job return '(' . implode(' | ', $name) . ')'; } } -?> \ No newline at end of file +?> From 0cfb2d20190a501ec84c7308678d627a2bc16558 Mon Sep 17 00:00:00 2001 From: warezthebeef Date: Fri, 19 Aug 2011 12:33:05 +1200 Subject: [PATCH 09/13] Fixed job arguments being wiped by array_shift --- lib/Resque/Job.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index c820412..ee4aaba 100644 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -128,7 +128,7 @@ class Resque_Job return array(); } - return array_shift($this->payload['args']); + return $this->payload['args'][0]; } /** From 700af834b4e0d707badf78bc23a11112d772d110 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Fri, 16 Sep 2011 15:30:36 +1000 Subject: [PATCH 10/13] Unit tests should not be directly accessing payload[args] now that we have getArguments() --- test/Resque/Tests/JobTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Resque/Tests/JobTest.php b/test/Resque/Tests/JobTest.php index df6187b..1f33fee 100644 --- a/test/Resque/Tests/JobTest.php +++ b/test/Resque/Tests/JobTest.php @@ -65,7 +65,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase Resque::enqueue('jobs', 'Test_Job', $args); $job = Resque_Job::reserve('jobs'); - $this->assertEquals($args, $job->payload['args']); + $this->assertEquals($args, $job->getArguments()); } public function testAfterJobIsReservedItIsRemoved() @@ -97,7 +97,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase $newJob = Resque_Job::reserve('jobs'); $this->assertEquals($job->payload['class'], $newJob->payload['class']); - $this->assertEquals($job->payload['args'], $newJob->payload['args']); + $this->assertEquals($job->payload['args'], $newJob->getArguments()); } public function testFailedJobExceptionsAreCaught() From c90e21d88eb2a495c52dfb81d95b3af701995029 Mon Sep 17 00:00:00 2001 From: d11wtq Date: Sat, 24 Sep 2011 15:08:53 +1000 Subject: [PATCH 11/13] 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. --- lib/Redisent/Redisent.php | 4 ++++ lib/Resque/Worker.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/Redisent/Redisent.php b/lib/Redisent/Redisent.php index ac70c81..19f5cdf 100644 --- a/lib/Redisent/Redisent.php +++ b/lib/Redisent/Redisent.php @@ -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}"); diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index a5c70b9..3e7eefc 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -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,15 @@ 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. From 3514a4f063ce529954ab531e359cfb4317e8410d Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 24 Sep 2011 15:40:20 +1000 Subject: [PATCH 12/13] Move brace to new line --- lib/Resque/Worker.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index 3e7eefc..a180d27 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -385,7 +385,8 @@ class Resque_Worker * 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() { + public function reestablishRedisConnection() + { $this->log('SIGPIPE received; attempting to reconnect'); Resque::redis()->establishConnection(); } From 4c025119cc91fe160caf50959f0d28dd5daa1734 Mon Sep 17 00:00:00 2001 From: Chris Boulton Date: Sat, 24 Sep 2011 15:42:28 +1000 Subject: [PATCH 13/13] Update changelog --- CHANGELOG.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index ba4193d..84ae07c 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -2,6 +2,8 @@ * Allow alternate redis database to be selected when calling setBackend by supplying a second argument (patrickbajao) * Use `require_once` when including php-resque after the app has been included in the sample resque.php to prevent include conflicts (andrewjshults) +* Wrap job arguments in an array to improve compatibility with ruby resque (warezthebeef) +* 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) ## 1.1 (2011-03-27) ##