Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions src/Illuminate/Queue/Events/QueuePaused.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Illuminate\Queue\Events;

class QueuePaused
{
/**
* Create a new event instance.
*
* @param string $connection The connection name.
* @param string $queue The queue name.
* @param \DateTimeInterface|\DateInterval|int|null $ttl
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, we can slightly narrow this

Suggested change
* @param \DateTimeInterface|\DateInterval|int|null $ttl
* @param \DateTimeInterface|\DateInterval|non-negative-int|null $ttl

*/
public function __construct(
public $connection,
public $queue,
public $ttl = null,
) {
}
}
18 changes: 18 additions & 0 deletions src/Illuminate/Queue/Events/QueueResumed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Illuminate\Queue\Events;

class QueueResumed
{
/**
* Create a new event instance.
*
* @param string $connection The connection name.
* @param string $queue The queue name.
*/
public function __construct(
public $connection,
public $queue,
) {
}
}
12 changes: 12 additions & 0 deletions src/Illuminate/Queue/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ public function pause($connection, $queue)
$this->app['cache']
->store()
->forever("illuminate:queue:paused:{$connection}:{$queue}", true);

$this->app['events']->dispatch(
new Events\QueuePaused($connection, $queue)
);
}

/**
Expand All @@ -224,6 +228,10 @@ public function pauseFor($connection, $queue, $ttl)
$this->app['cache']
->store()
->put("illuminate:queue:paused:{$connection}:{$queue}", true, $ttl);

$this->app['events']->dispatch(
new Events\QueuePaused($connection, $queue, $ttl)
);
}

/**
Expand All @@ -238,6 +246,10 @@ public function resume($connection, $queue)
$this->app['cache']
->store()
->forget("illuminate:queue:paused:{$connection}:{$queue}");

$this->app['events']->dispatch(
new Events\QueueResumed($connection, $queue)
);
}

/**
Expand Down
57 changes: 57 additions & 0 deletions tests/Queue/QueuePauseResumeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use Illuminate\Cache\ArrayStore;
use Illuminate\Cache\Repository;
use Illuminate\Events\Dispatcher;
use Illuminate\Queue\Console\Concerns\ParsesQueue;
use Illuminate\Queue\Events\QueuePaused;
use Illuminate\Queue\Events\QueueResumed;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Carbon;
use Mockery as m;
Expand Down Expand Up @@ -32,6 +35,7 @@ protected function setUp(): void
'queue.connections.database' => ['driver' => 'database'],
],
'cache' => $cacheMock,
'events' => new Dispatcher(),
];

$this->manager = new QueueManager($app);
Expand Down Expand Up @@ -110,6 +114,59 @@ public function testResumingOnlyAffectsSpecificQueue()
$this->assertTrue($this->manager->isPaused('redis', 'notifications'));
}

public function testPauseDispatchesQueuePausedEvent()
{
$dispatchedEvent = null;

$dispatcher = $this->manager->getApplication()['events'];

$dispatcher->listen(QueuePaused::class, function ($event) use (&$dispatchedEvent) {
$dispatchedEvent = $event;
});

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

$this->assertInstanceOf(QueuePaused::class, $dispatchedEvent);
$this->assertSame('redis', $dispatchedEvent->connection);
$this->assertSame('default', $dispatchedEvent->queue);
$this->assertNull($dispatchedEvent->ttl);
}

public function testPauseForDispatchesQueuePausedEventWithTTL()
{
$dispatchedEvent = null;

$dispatcher = $this->manager->getApplication()['events'];

$dispatcher->listen(QueuePaused::class, function ($event) use (&$dispatchedEvent) {
$dispatchedEvent = $event;
});

$this->manager->pauseFor('redis', 'emails', 60);

$this->assertInstanceOf(QueuePaused::class, $dispatchedEvent);
$this->assertSame('redis', $dispatchedEvent->connection);
$this->assertSame('emails', $dispatchedEvent->queue);
$this->assertSame(60, $dispatchedEvent->ttl);
}

public function testResumeDispatchesQueueResumedEvent()
{
$dispatchedEvent = null;

$dispatcher = $this->manager->getApplication()['events'];

$dispatcher->listen(QueueResumed::class, function ($event) use (&$dispatchedEvent) {
$dispatchedEvent = $event;
});

$this->manager->resume('database', 'notifications');

$this->assertInstanceOf(QueueResumed::class, $dispatchedEvent);
$this->assertSame('database', $dispatchedEvent->connection);
$this->assertSame('notifications', $dispatchedEvent->queue);
}

public function testParsingQueueString()
{
$parser = new class()
Expand Down
Loading