diff --git a/src/AzureQueue.php b/src/AzureQueue.php index 634095b..0423572 100644 --- a/src/AzureQueue.php +++ b/src/AzureQueue.php @@ -2,8 +2,10 @@ namespace Squigg\AzureQueueLaravel; +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; @@ -11,7 +13,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 +125,25 @@ public function pop($queue = null) return null; } + /** + * Delete all the jobs from the queue. + * + * @param string $queue + * @return void + */ + public function clear($queue) + { + try { + $this->azure->clearMessages($this->getQueue($queue)); + } catch (ServiceException $exception) { + if ($exception->getErrorText() === 'OperationTimedOut') { + $this->clear($queue); + } else { + throw $exception; + } + } + } + /** * Get the queue or return the default. *