From c3dba267349da3465624e69db0a457fd3343849f Mon Sep 17 00:00:00 2001 From: rinocella Date: Mon, 10 Jun 2024 11:15:15 +0200 Subject: [PATCH 1/4] fix: fixed pop on default queue when not specifically added --- src/Illuminate/Queue/BeanstalkdQueue.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Queue/BeanstalkdQueue.php b/src/Illuminate/Queue/BeanstalkdQueue.php index f6f6a71ee2d5..79314842b24f 100755 --- a/src/Illuminate/Queue/BeanstalkdQueue.php +++ b/src/Illuminate/Queue/BeanstalkdQueue.php @@ -169,9 +169,14 @@ public function bulk($jobs, $data = '', $queue = null) public function pop($queue = null) { $queue = $this->getQueue($queue); - - $this->pheanstalk->watch(new TubeName($queue)); - + $newTube = new TubeName($queue); + $this->pheanstalk->watch($newTube); + $watched = $this->pheanstalk->listTubesWatched(); + foreach ($watched as $w){ + if($w->value !== $newTube->value){ + $this->pheanstalk->ignore($w); + } + } $job = $this->pheanstalk->reserveWithTimeout($this->blockFor); if ($job instanceof JobIdInterface) { From 1a31cf2dd89d66f8c82be8cb50fd8c05a2a2a798 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 10 Jun 2024 10:22:33 -0500 Subject: [PATCH 2/4] formatting --- src/Illuminate/Queue/BeanstalkdQueue.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Queue/BeanstalkdQueue.php b/src/Illuminate/Queue/BeanstalkdQueue.php index 79314842b24f..b1b24da35c64 100755 --- a/src/Illuminate/Queue/BeanstalkdQueue.php +++ b/src/Illuminate/Queue/BeanstalkdQueue.php @@ -168,15 +168,16 @@ public function bulk($jobs, $data = '', $queue = null) */ public function pop($queue = null) { - $queue = $this->getQueue($queue); - $newTube = new TubeName($queue); - $this->pheanstalk->watch($newTube); - $watched = $this->pheanstalk->listTubesWatched(); - foreach ($watched as $w){ - if($w->value !== $newTube->value){ - $this->pheanstalk->ignore($w); + $this->pheanstalk->watch( + $tube = new TubeName($queue = $this->getQueue($queue)) + ); + + foreach ($this->pheanstalk->listTubesWatched() as $watched) { + if ($watched->value !== $tube->value) { + $this->pheanstalk->ignore($watched); } } + $job = $this->pheanstalk->reserveWithTimeout($this->blockFor); if ($job instanceof JobIdInterface) { From d18a149e4ac06652f58cbb698bac742799dafcae Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Jun 2024 16:53:31 +0800 Subject: [PATCH 3/4] wip Signed-off-by: Mior Muhammad Zaki --- tests/Queue/QueueBeanstalkdQueueTest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/Queue/QueueBeanstalkdQueueTest.php b/tests/Queue/QueueBeanstalkdQueueTest.php index 3ff9213a8a5d..d02e3f7e0f4f 100755 --- a/tests/Queue/QueueBeanstalkdQueueTest.php +++ b/tests/Queue/QueueBeanstalkdQueueTest.php @@ -7,14 +7,15 @@ use Illuminate\Queue\Jobs\BeanstalkdJob; use Illuminate\Support\Str; use Mockery as m; +use PHPUnit\Framework\TestCase; use Pheanstalk\Contract\JobIdInterface; use Pheanstalk\Contract\PheanstalkManagerInterface; use Pheanstalk\Contract\PheanstalkPublisherInterface; use Pheanstalk\Contract\PheanstalkSubscriberInterface; use Pheanstalk\Pheanstalk; use Pheanstalk\Values\Job; +use Pheanstalk\Values\TubeList; use Pheanstalk\Values\TubeName; -use PHPUnit\Framework\TestCase; class QueueBeanstalkdQueueTest extends TestCase { @@ -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, ''); @@ -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, ''); From c755e28747ea2dc28bcc83f77a0081a2a222e0fc Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Jun 2024 16:58:35 +0800 Subject: [PATCH 4/4] wip Signed-off-by: Mior Muhammad Zaki --- tests/Queue/QueueBeanstalkdQueueTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Queue/QueueBeanstalkdQueueTest.php b/tests/Queue/QueueBeanstalkdQueueTest.php index d02e3f7e0f4f..ba34a7069305 100755 --- a/tests/Queue/QueueBeanstalkdQueueTest.php +++ b/tests/Queue/QueueBeanstalkdQueueTest.php @@ -7,7 +7,6 @@ use Illuminate\Queue\Jobs\BeanstalkdJob; use Illuminate\Support\Str; use Mockery as m; -use PHPUnit\Framework\TestCase; use Pheanstalk\Contract\JobIdInterface; use Pheanstalk\Contract\PheanstalkManagerInterface; use Pheanstalk\Contract\PheanstalkPublisherInterface; @@ -16,6 +15,7 @@ use Pheanstalk\Values\Job; use Pheanstalk\Values\TubeList; use Pheanstalk\Values\TubeName; +use PHPUnit\Framework\TestCase; class QueueBeanstalkdQueueTest extends TestCase {