From e412501e42f60ab3d84ed737530c70061420b78e Mon Sep 17 00:00:00 2001 From: Bjoern Boschman Date: Thu, 23 Apr 2015 16:07:04 +0200 Subject: [PATCH 1/4] prevents workers to stale when redis server went away --- lib/Resque/Worker.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index 379b853e..0c36bc0b 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -154,6 +154,21 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false) if($this->shutdown) { break; } + + // is redis still alive? + try { + if (Resque::redis()->ping() === false) { + $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); + Resque::$redis = null; + usleep($interval * 1000000); + continue; + } + } catch (CredisException $e) { + $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); + Resque::$redis = null; + usleep($interval * 1000000); + continue; + } // Attempt to find and reserve a job $job = false; From e3b0ad529477a80d92b07ff796e7901206430b8b Mon Sep 17 00:00:00 2001 From: Bjoern Boschman Date: Fri, 24 Apr 2015 11:39:48 +0200 Subject: [PATCH 2/4] updated first error handler to throw a credisexception as suggested on #243 pull request --- lib/Resque/Worker.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index 0c36bc0b..bfea27ff 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -158,10 +158,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false) // is redis still alive? try { if (Resque::redis()->ping() === false) { - $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); - Resque::$redis = null; - usleep($interval * 1000000); - continue; + throw new CredisException(); } } catch (CredisException $e) { $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); From c21cda84b8dc36d504e5828ad8fc01420341e7e4 Mon Sep 17 00:00:00 2001 From: Bjoern Boschman Date: Tue, 16 Jun 2015 10:41:25 +0200 Subject: [PATCH 3/4] CredisException needs to have a message in its constructor --- lib/Resque/Worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index bfea27ff..a99542f7 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -158,7 +158,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false) // is redis still alive? try { if (Resque::redis()->ping() === false) { - throw new CredisException(); + throw new CredisException('redis ping() failed'); } } catch (CredisException $e) { $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); From 6ee62958aeae70aab9aaa5ad3f9c14271c83a1ef Mon Sep 17 00:00:00 2001 From: Bjoern Boschman Date: Tue, 8 Mar 2016 12:15:44 +0100 Subject: [PATCH 4/4] removed all closing PHP tags --- lib/Resque/Exception.php | 1 - lib/Resque/Failure/Interface.php | 1 - lib/Resque/Failure/Redis.php | 1 - lib/Resque/Job.php | 1 - lib/Resque/Job/Status.php | 1 - lib/Resque/Worker.php | 1 - 6 files changed, 6 deletions(-) diff --git a/lib/Resque/Exception.php b/lib/Resque/Exception.php index 60cca86f..01217c38 100644 --- a/lib/Resque/Exception.php +++ b/lib/Resque/Exception.php @@ -9,4 +9,3 @@ class Resque_Exception extends Exception { } -?> \ No newline at end of file diff --git a/lib/Resque/Failure/Interface.php b/lib/Resque/Failure/Interface.php index b7e5bc83..74de9e7b 100644 --- a/lib/Resque/Failure/Interface.php +++ b/lib/Resque/Failure/Interface.php @@ -18,4 +18,3 @@ interface Resque_Failure_Interface */ public function __construct($payload, $exception, $worker, $queue); } -?> \ No newline at end of file diff --git a/lib/Resque/Failure/Redis.php b/lib/Resque/Failure/Redis.php index cfac5b6c..69d68724 100644 --- a/lib/Resque/Failure/Redis.php +++ b/lib/Resque/Failure/Redis.php @@ -31,4 +31,3 @@ public function __construct($payload, $exception, $worker, $queue) Resque::redis()->rpush('failed', $data); } } -?> \ No newline at end of file diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index ca21445a..16b55d0e 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -269,4 +269,3 @@ public function __toString() return '(' . implode(' | ', $name) . ')'; } } -?> diff --git a/lib/Resque/Job/Status.php b/lib/Resque/Job/Status.php index ffa351ba..00fc40c5 100644 --- a/lib/Resque/Job/Status.php +++ b/lib/Resque/Job/Status.php @@ -140,4 +140,3 @@ public function __toString() return 'job:' . $this->id . ':status'; } } -?> \ No newline at end of file diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index a99542f7..5c6ee4ff 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -576,4 +576,3 @@ public function setLogger(Psr\Log\LoggerInterface $logger) $this->logger = $logger; } } -?>