From 3955bc8edc410c68c57e44120b709465101e090a Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Thu, 1 Nov 2012 09:28:47 -0400 Subject: [PATCH 1/6] Updated recreate method in Resque_Job class to set arguments in the same fashion as getAruments returns them. --- 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 661bd3c..e673c4f 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -231,7 +231,7 @@ class Resque_Job $monitor = true; } - return self::create($this->queue, $this->payload['class'], $this->payload['args'], $monitor); + return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); } /** From f6334bb3b89a604e36440065b36e0de6ac96207a Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Thu, 1 Nov 2012 09:37:06 -0400 Subject: [PATCH 2/6] Added a check to see if we have args before we attempt to access the first item in the payload args to prevent an undefined index error. --- lib/Resque/Job.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index e673c4f..0e03f04 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -230,8 +230,9 @@ class Resque_Job if($status->isTracking()) { $monitor = true; } - - return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); + $args = count($this->payload['args'])? $this->payload['args'][0] : $this->payload['args']; + + return self::create($this->queue, $this->payload['class'], $args, $monitor); } /** From e4f39a60931e68e83d963c44d8c42615ec70f188 Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 09:33:09 -0500 Subject: [PATCH 3/6] Updated Redisent.php to attempt three reconnects to the redis server before giving up. Also supressed fwrite errors. --- lib/Redisent/Redisent.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/Redisent/Redisent.php b/lib/Redisent/Redisent.php index 4b480f6..727f16b 100644 --- a/lib/Redisent/Redisent.php +++ b/lib/Redisent/Redisent.php @@ -43,6 +43,13 @@ class Redisent { * @access public */ public $port; + + /** + * Number of times to attempt a reconnect + * + * @var int + */ + public $max_reconnects = 3; /** * Creates a Redisent connection to the Redis server on host {@link $host} and port {@link $port}. @@ -73,10 +80,17 @@ class Redisent { $command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF); /* Open a Redis connection and execute the command */ + $reconnects = 0; for ($written = 0; $written < strlen($command); $written += $fwrite) { - $fwrite = fwrite($this->__sock, substr($command, $written)); - if ($fwrite === FALSE) { - throw new Exception('Failed to write entire command to stream'); + $fwrite = @fwrite($this->__sock, substr($command, $written)); + if ($fwrite === FALSE || $fwrite === 0) { + if ($reconnects >= (int)$this->max_reconnects) { + throw new Exception('Failed to write entire command to stream'); + }else{ + fclose($this->__sock); + $this->establishConnection(); + $reconnects++; + } } } From 0afb87663f113cd09d411621beb7c7b72bc89253 Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 10:33:32 -0500 Subject: [PATCH 4/6] Reverted changes made to upstream master. --- lib/Resque/Job.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 0e03f04..e673c4f 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -230,9 +230,8 @@ class Resque_Job if($status->isTracking()) { $monitor = true; } - $args = count($this->payload['args'])? $this->payload['args'][0] : $this->payload['args']; - - return self::create($this->queue, $this->payload['class'], $args, $monitor); + + return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); } /** From a5b70a5cbd087f2b2c697a698a8ff64074535203 Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 10:39:34 -0500 Subject: [PATCH 5/6] Added a sleep call for a second before establishing another connection. --- lib/Redisent/Redisent.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Redisent/Redisent.php b/lib/Redisent/Redisent.php index 727f16b..92ccd02 100644 --- a/lib/Redisent/Redisent.php +++ b/lib/Redisent/Redisent.php @@ -88,6 +88,7 @@ class Redisent { throw new Exception('Failed to write entire command to stream'); }else{ fclose($this->__sock); + sleep(1); $this->establishConnection(); $reconnects++; } From fdc9f881e8b40cdb4a3fdb540ac1afdce0a0ca2f Mon Sep 17 00:00:00 2001 From: Allen Torres Date: Fri, 28 Dec 2012 10:42:16 -0500 Subject: [PATCH 6/6] Reverted changes made from upstream master. --- 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 e673c4f..661bd3c 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -231,7 +231,7 @@ class Resque_Job $monitor = true; } - return self::create($this->queue, $this->payload['class'], $this->payload['args'][0], $monitor); + return self::create($this->queue, $this->payload['class'], $this->payload['args'], $monitor); } /**