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

[12.x] Add ability to ignore queuePaused \ queueShouldRestart cache checks#57975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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
26 changes: 26 additions & 0 deletionssrc/Illuminate/Queue/Worker.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,6 +106,20 @@ class Worker
*/
public static $memoryExceededExitCode;

/**
* Indicates if the worker should check for the restart signal in the cache.
*
* @var bool
*/
public static $restartable = true;

/**
* Indicates if the worker should check for the paused signal in the cache.
*
* @var bool
*/
public static $pausable = true;

/**
* Create a new queue worker.
*
Expand DownExpand Up@@ -400,6 +414,10 @@ protected function getNextJob($connection, $queue)
*/
protected function queuePaused($connectionName, $queue)
{
if (! static::$pausable) {
return false;
}

return $this->cache && (bool) $this->cache->get(
"illuminate:queue:paused:{$connectionName}:{$queue}", false
);
Expand DownExpand Up@@ -740,6 +758,10 @@ protected function raiseExceptionOccurredJobEvent($connectionName, $job, Throwab
*/
protected function queueShouldRestart($lastRestart)
{
if (! static::$restartable) {
return false;
}

return $this->getTimestampOfLastQueueRestart() != $lastRestart;
}

Expand All@@ -750,6 +772,10 @@ protected function queueShouldRestart($lastRestart)
*/
protected function getTimestampOfLastQueueRestart()
{
if (! static::$restartable) {
return null;
}

if ($this->cache) {
return $this->cache->get('illuminate:queue:restart');
}
Expand Down
62 changes: 62 additions & 0 deletionstests/Integration/Queue/WorkCommandTest.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@
namespace Illuminate\Tests\Integration\Queue;

use Illuminate\Bus\Queueable;
use Illuminate\Cache\CacheManager;
use Illuminate\Cache\Repository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\UniqueConstraintViolationException;
use Illuminate\Foundation\Bus\Dispatchable;
Expand All@@ -12,6 +14,7 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Exceptions;
use Illuminate\Support\Facades\Queue;
use Mockery as m;
use Orchestra\Testbench\Attributes\WithMigration;
use RuntimeException;

Expand DownExpand Up@@ -184,6 +187,65 @@ public function testMemoryExitCode()
Worker::$memoryExceededExitCode = null;
}

public function testDisableLastRestartCheck()
{
$this->markTestSkippedWhenUsingQueueDrivers(['redis', 'beanstalkd']);

Worker::$restartable = false;

$cache = m::mock(Repository::class);
$cache->shouldNotReceive('get')->with('illuminate:queue:restart');
$cache->shouldReceive('get')->with(m::pattern('/^illuminate:queue:paused:/'), false);

$cacheManager = m::mock(CacheManager::class);
$cacheManager->shouldReceive('driver')->andReturn($cache);
$cacheManager->shouldReceive('store')->andReturn($cache);

$this->app->instance('cache', $cacheManager);

Queue::push(new FirstJob);

$this->artisan('queue:work', [
'--max-jobs' => 1,
'--stop-when-empty' => true,
]);

$this->assertSame(0, Queue::size());
$this->assertTrue(FirstJob::$ran);

Worker::$restartable = true;
}

public function testDisablePauseQueueCheck()
{
$this->markTestSkippedWhenUsingQueueDrivers(['redis', 'beanstalkd']);

Worker::$pausable = false;

$cache = m::mock(Repository::class);

$cache->shouldReceive('get')->with('illuminate:queue:restart')->andReturn(null);
$cache->shouldNotReceive('get')->with(m::pattern('/^illuminate:queue:paused:/'), false);

$cacheManager = m::mock(CacheManager::class);
$cacheManager->shouldReceive('driver')->andReturn($cache);
$cacheManager->shouldReceive('store')->andReturn($cache);

$this->app->instance('cache', $cacheManager);

Queue::push(new FirstJob);

$this->artisan('queue:work', [
'--max-jobs' => 1,
'--stop-when-empty' => true,
]);

$this->assertSame(0, Queue::size());
$this->assertTrue(FirstJob::$ran);

Worker::$pausable = true;
}

public function testFailedJobListenerOnlyRunsOnce()
{
$this->markTestSkippedWhenUsingQueueDrivers(['redis', 'beanstalkd']);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp