Skip to content

Commit

Permalink
[11.x] Fixed pop on default Beankstalkd queue when not specifically a…
Browse files Browse the repository at this point in the history
…dded (#51759)

* fix: fixed pop on default queue when not specifically added

* formatting

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: rinocella <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
Co-authored-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
4 people authored Jun 11, 2024
1 parent 7be701d commit da50eea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Illuminate/Queue/BeanstalkdQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,15 @@ public function bulk($jobs, $data = '', $queue = null)
*/
public function pop($queue = null)
{
$queue = $this->getQueue($queue);
$this->pheanstalk->watch(
$tube = new TubeName($queue = $this->getQueue($queue))
);

$this->pheanstalk->watch(new TubeName($queue));
foreach ($this->pheanstalk->listTubesWatched() as $watched) {
if ($watched->value !== $tube->value) {
$this->pheanstalk->ignore($watched);
}
}

$job = $this->pheanstalk->reserveWithTimeout($this->blockFor);

Expand Down
11 changes: 9 additions & 2 deletions tests/Queue/QueueBeanstalkdQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Pheanstalk\Contract\PheanstalkSubscriberInterface;
use Pheanstalk\Pheanstalk;
use Pheanstalk\Values\Job;
use Pheanstalk\Values\TubeList;
use Pheanstalk\Values\TubeName;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -80,9 +81,12 @@ public function testDelayedPushProperlyPushesJobOntoBeanstalkd()
public function testPopProperlyPopsJobOffOfBeanstalkd()
{
$this->setQueue('default', 60);
$tube = new TubeName('default');

$pheanstalk = $this->queue->getPheanstalk();
$pheanstalk->shouldReceive('watch')->once()->with(m::type(TubeName::class));
$pheanstalk->shouldReceive('watch')->once()->with(m::type(TubeName::class))
->shouldReceive('listTubesWatched')->once()->andReturn(new TubeList($tube));

$jobId = m::mock(JobIdInterface::class);
$jobId->shouldReceive('getId')->once();
$job = new Job($jobId, '');
Expand All @@ -96,9 +100,12 @@ public function testPopProperlyPopsJobOffOfBeanstalkd()
public function testBlockingPopProperlyPopsJobOffOfBeanstalkd()
{
$this->setQueue('default', 60, 60);
$tube = new TubeName('default');

$pheanstalk = $this->queue->getPheanstalk();
$pheanstalk->shouldReceive('watch')->once()->with(m::type(TubeName::class));
$pheanstalk->shouldReceive('watch')->once()->with(m::type(TubeName::class))
->shouldReceive('listTubesWatched')->once()->andReturn(new TubeList($tube));

$jobId = m::mock(JobIdInterface::class);
$jobId->shouldReceive('getId')->once();
$job = new Job($jobId, '');
Expand Down

0 comments on commit da50eea

Please sign in to comment.