Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Illuminate/Queue/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ public function pause($connection, $queue)
->forever("illuminate:queue:paused:{$connection}:{$queue}", true);
}

/**
* Pause a queue by its connection and name for a given number of seconds.
*
* @param string $connection
* @param string $queue
* @param int $seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param int $seconds
* @param int|null $seconds

As demonstrated in the testPauseQueueIndefinitely() test $seconds can accept null.

* @return void
*/
public function pauseFor($connection, $queue, $seconds)
{
$this->app['cache']
->store()
->put("illuminate:queue:paused:{$connection}:{$queue}", true, $seconds);
}

/**
* Resume a paused queue by its connection and name.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @method static bool connected(string|null $name = null)
* @method static \Illuminate\Contracts\Queue\Queue connection(string|null $name = null)
* @method static void pause(string $connection, string $queue)
* @method static void pauseFor(string $connection, string $queue, int $seconds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @method static void pauseFor(string $connection, string $queue, int $seconds)
* @method static void pauseFor(string $connection, string $queue, int|null $seconds)

* @method static void resume(string $connection, string $queue)
* @method static bool isPaused(string $connection, string $queue)
* @method static void extend(string $driver, \Closure $resolver)
Expand Down
13 changes: 11 additions & 2 deletions tests/Queue/QueuePauseResumeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Cache\Repository;
use Illuminate\Queue\Console\Concerns\ParsesQueue;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Carbon;
use Mockery as m;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -51,15 +52,23 @@ public function testPauseQueueWithConnection()

public function testPauseQueueWithTTL()
{
$this->manager->pause('redis', 'default', 60);
Carbon::setTestNow();
$this->manager->pauseFor('redis', 'default', 30);

$this->assertTrue($this->manager->isPaused('redis', 'default'));

Carbon::setTestNow(Carbon::now()->addMinute());
$this->assertFalse($this->manager->isPaused('redis', 'default'));
}

public function testPauseQueueIndefinitely()
{
$this->manager->pause('redis', 'default', null);
Carbon::setTestNow();
$this->manager->pause('redis', 'default');

$this->assertTrue($this->manager->isPaused('redis', 'default'));

Carbon::setTestNow(Carbon::now()->addYear());
$this->assertTrue($this->manager->isPaused('redis', 'default'));
}

Expand Down