Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec28c3d

Browse files
committed
add static properties and tests
1 parent263ea42 commitec28c3d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

‎src/Illuminate/Queue/Worker.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ class Worker
106106
*/
107107
publicstatic$memoryExceededExitCode;
108108

109+
/**
110+
* Indicates if the worker should check for restart.
111+
*
112+
* @var bool
113+
*/
114+
publicstatic$checkRestart =true;
115+
116+
/**
117+
* Indicates if the worker should check for paused queues.
118+
*
119+
* @var bool
120+
*/
121+
publicstatic$checkPaused =true;
122+
109123
/**
110124
* Create a new queue worker.
111125
*
@@ -400,6 +414,10 @@ protected function getNextJob($connection, $queue)
400414
*/
401415
protectedfunctionqueuePaused($connectionName,$queue)
402416
{
417+
if (!static::$checkPaused) {
418+
returnfalse;
419+
}
420+
403421
return$this->cache && (bool)$this->cache->get(
404422
"illuminate:queue:paused:{$connectionName}:{$queue}",false
405423
);
@@ -750,6 +768,10 @@ protected function queueShouldRestart($lastRestart)
750768
*/
751769
protectedfunctiongetTimestampOfLastQueueRestart()
752770
{
771+
if (!static::$checkRestart) {
772+
returnnull;
773+
}
774+
753775
if ($this->cache) {
754776
return$this->cache->get('illuminate:queue:restart');
755777
}

‎tests/Integration/Queue/WorkCommandTest.php‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespaceIlluminate\Tests\Integration\Queue;
44

55
useIlluminate\Bus\Queueable;
6+
useIlluminate\Cache\CacheManager;
7+
useIlluminate\Cache\Repository;
68
useIlluminate\Contracts\Queue\ShouldQueue;
79
useIlluminate\Database\UniqueConstraintViolationException;
810
useIlluminate\Foundation\Bus\Dispatchable;
@@ -12,6 +14,7 @@
1214
useIlluminate\Support\Facades\Artisan;
1315
useIlluminate\Support\Facades\Exceptions;
1416
useIlluminate\Support\Facades\Queue;
17+
useMockery;
1518
useOrchestra\Testbench\Attributes\WithMigration;
1619
useRuntimeException;
1720

@@ -184,6 +187,59 @@ public function testMemoryExitCode()
184187
Worker::$memoryExceededExitCode =null;
185188
}
186189

190+
publicfunctiontestDisableRestartCheck()
191+
{
192+
$this->markTestSkippedWhenUsingQueueDrivers(['redis','beanstalkd']);
193+
194+
Worker::$checkRestart =false;
195+
196+
$cache = Mockery::mock(Repository::class);
197+
$cache->shouldNotReceive('get')->with('illuminate:queue:restart');
198+
199+
$cacheManager = Mockery::mock(CacheManager::class);
200+
$cacheManager->shouldReceive('driver')->andReturn($cache);
201+
$cacheManager->shouldReceive('store')->andReturn($cache);
202+
203+
$this->app->instance('cache',$cacheManager);
204+
205+
Queue::push(newFirstJob);
206+
207+
$this->artisan('queue:work', [
208+
'--max-jobs' =>1,
209+
'--stop-when-empty' =>true,
210+
]);
211+
212+
Worker::$checkRestart =true;
213+
}
214+
215+
publicfunctiontestDisablePauseCheck()
216+
{
217+
$this->markTestSkippedWhenUsingQueueDrivers(['redis','beanstalkd']);
218+
219+
Worker::$checkPaused =false;
220+
221+
$cache = Mockery::mock(Repository::class);
222+
223+
$cache->shouldReceive('get')->with('illuminate:queue:restart')->andReturn(null);
224+
225+
$cache->shouldNotReceive('get')->with(Mockery::pattern('/^illuminate:queue:paused:/'),false);
226+
227+
$cacheManager = Mockery::mock(CacheManager::class);
228+
$cacheManager->shouldReceive('driver')->andReturn($cache);
229+
$cacheManager->shouldReceive('store')->andReturn($cache);
230+
231+
$this->app->instance('cache',$cacheManager);
232+
233+
Queue::push(newFirstJob);
234+
235+
$this->artisan('queue:work', [
236+
'--max-jobs' =>1,
237+
'--stop-when-empty' =>true,
238+
]);
239+
240+
Worker::$checkPaused =true;
241+
}
242+
187243
publicfunctiontestFailedJobListenerOnlyRunsOnce()
188244
{
189245
$this->markTestSkippedWhenUsingQueueDrivers(['redis','beanstalkd']);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp