From 028469aa420a18ab33c16d38da75d21687279911 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Wed, 16 Sep 2020 21:34:51 +0200 Subject: [PATCH] allow clearing sqs queues --- src/Illuminate/Queue/SqsQueue.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Queue/SqsQueue.php b/src/Illuminate/Queue/SqsQueue.php index 80a08decbe5d..b54d731240fe 100755 --- a/src/Illuminate/Queue/SqsQueue.php +++ b/src/Illuminate/Queue/SqsQueue.php @@ -3,11 +3,12 @@ namespace Illuminate\Queue; use Aws\Sqs\SqsClient; +use Illuminate\Contracts\Queue\ClearableQueue; use Illuminate\Contracts\Queue\Queue as QueueContract; use Illuminate\Queue\Jobs\SqsJob; use Illuminate\Support\Str; -class SqsQueue extends Queue implements QueueContract +class SqsQueue extends Queue implements QueueContract, ClearableQueue { /** * The Amazon SQS instance. @@ -139,6 +140,23 @@ public function pop($queue = null) } } + /** + * Delete all of the jobs from the queue. + * + * @param string $queue + * @return int + */ + public function clear($queue) + { + $size = $this->size($queue); + + $this->sqs->purgeQueue([ + 'QueueUrl' => $this->getQueue($queue), + ]); + + return $size; + } + /** * Get the queue or return the default. *