From 401dc3683ac274030cdd50287139f927a9ff28e5 Mon Sep 17 00:00:00 2001 From: Rik Morskate Date: Sun, 17 Jul 2022 14:58:02 +0200 Subject: [PATCH 1/6] Make the queue clearable --- src/AzureQueue.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/AzureQueue.php b/src/AzureQueue.php index 634095b..73dc839 100644 --- a/src/AzureQueue.php +++ b/src/AzureQueue.php @@ -2,6 +2,7 @@ namespace Squigg\AzureQueueLaravel; +use Illuminate\Contracts\Queue\ClearableQueue; use Illuminate\Contracts\Queue\Queue as QueueInterface; use Illuminate\Queue\Queue; use MicrosoftAzure\Storage\Queue\Internal\IQueue; @@ -11,7 +12,7 @@ use MicrosoftAzure\Storage\Queue\Models\ListMessagesResult; use MicrosoftAzure\Storage\Queue\QueueRestProxy; -class AzureQueue extends Queue implements QueueInterface +class AzureQueue extends Queue implements QueueInterface, ClearableQueue { /** @@ -123,6 +124,17 @@ public function pop($queue = null) return null; } + /** + * Delete all of the jobs from the queue. + * + * @param string $queue + * @return int + */ + public function clear($queue) + { + $this->azure->clearMessages($this->getQueue($queue)); + } + /** * Get the queue or return the default. * From 068503259cf0bf7fbd3a77f27378aa9afb2d90dc Mon Sep 17 00:00:00 2001 From: Rik Morskate Date: Sun, 17 Jul 2022 21:56:49 +0200 Subject: [PATCH 2/6] Correct description --- src/AzureQueue.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AzureQueue.php b/src/AzureQueue.php index 73dc839..d98f10c 100644 --- a/src/AzureQueue.php +++ b/src/AzureQueue.php @@ -128,7 +128,6 @@ public function pop($queue = null) * Delete all of the jobs from the queue. * * @param string $queue - * @return int */ public function clear($queue) { From 0032f60f6bd518ef8a099a58e5b016f62c3371b1 Mon Sep 17 00:00:00 2001 From: Rik Morskate Date: Mon, 18 Jul 2022 09:24:28 +0200 Subject: [PATCH 3/6] Use async clear messages to support large queues --- src/AzureQueue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AzureQueue.php b/src/AzureQueue.php index d98f10c..2fcd571 100644 --- a/src/AzureQueue.php +++ b/src/AzureQueue.php @@ -131,7 +131,7 @@ public function pop($queue = null) */ public function clear($queue) { - $this->azure->clearMessages($this->getQueue($queue)); + $this->azure->clearMessagesAsync($this->getQueue($queue)); } /** From 1df2170589194679a27e14a8d5116bfed95bc4e7 Mon Sep 17 00:00:00 2001 From: Rik Morskate Date: Sat, 13 Aug 2022 10:47:46 +0200 Subject: [PATCH 4/6] Retry on service exception to delete all queue messages --- src/AzureQueue.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AzureQueue.php b/src/AzureQueue.php index 2fcd571..5bdf6d2 100644 --- a/src/AzureQueue.php +++ b/src/AzureQueue.php @@ -128,10 +128,15 @@ public function pop($queue = null) * Delete all of the jobs from the queue. * * @param string $queue + * @return void */ public function clear($queue) { - $this->azure->clearMessagesAsync($this->getQueue($queue)); + try { + $this->azure->clearMessages($this->getQueue($queue)); + } catch (ServiceException) { + $this->clear($queue); + } } /** From 55d1aec4a024fb06b517b330de37a6cc5fa8fb82 Mon Sep 17 00:00:00 2001 From: Rik Morskate Date: Sat, 13 Aug 2022 10:49:51 +0200 Subject: [PATCH 5/6] Added missing import --- src/AzureQueue.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AzureQueue.php b/src/AzureQueue.php index 5bdf6d2..e03b3b4 100644 --- a/src/AzureQueue.php +++ b/src/AzureQueue.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Queue\ClearableQueue; use Illuminate\Contracts\Queue\Queue as QueueInterface; use Illuminate\Queue\Queue; +use MicrosoftAzure\Storage\Common\Exceptions\ServiceException; use MicrosoftAzure\Storage\Queue\Internal\IQueue; use MicrosoftAzure\Storage\Queue\Models\CreateMessageOptions; use MicrosoftAzure\Storage\Queue\Models\GetQueueMetadataResult; From 527649cd9b655333adb12d198399c6918686482e Mon Sep 17 00:00:00 2001 From: Rik Morskate Date: Sun, 2 Oct 2022 21:43:45 +0200 Subject: [PATCH 6/6] Only catch OperationTimedOut exceptions --- src/AzureQueue.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/AzureQueue.php b/src/AzureQueue.php index e03b3b4..0423572 100644 --- a/src/AzureQueue.php +++ b/src/AzureQueue.php @@ -126,7 +126,7 @@ public function pop($queue = null) } /** - * Delete all of the jobs from the queue. + * Delete all the jobs from the queue. * * @param string $queue * @return void @@ -135,8 +135,12 @@ public function clear($queue) { try { $this->azure->clearMessages($this->getQueue($queue)); - } catch (ServiceException) { - $this->clear($queue); + } catch (ServiceException $exception) { + if ($exception->getErrorText() === 'OperationTimedOut') { + $this->clear($queue); + } else { + throw $exception; + } } }