diff --git a/src/Illuminate/Queue/SyncQueue.php b/src/Illuminate/Queue/SyncQueue.php index 0edd639c9e5c..33638c213a66 100755 --- a/src/Illuminate/Queue/SyncQueue.php +++ b/src/Illuminate/Queue/SyncQueue.php @@ -12,8 +12,6 @@ class SyncQueue extends Queue implements QueueContract { - protected $jobsCount = 0; - /** * Get the size of the queue. * @@ -39,8 +37,6 @@ public function push($job, $data = '', $queue = null) { $queueJob = $this->resolveJob($this->createPayload($job, $queue, $data), $queue); - $this->jobsCount++; - try { $this->raiseBeforeJobEvent($queueJob); @@ -49,8 +45,6 @@ public function push($job, $data = '', $queue = null) $this->raiseAfterJobEvent($queueJob); } catch (Throwable $e) { $this->handleException($queueJob, $e); - } finally { - $this->jobsCount--; } return 0; @@ -119,19 +113,11 @@ protected function raiseExceptionOccurredJobEvent(Job $job, Throwable $e) */ protected function handleException(Job $queueJob, Throwable $e) { - static $isGuarded = false; - - if ($isGuarded) { - $isGuarded = false; - } else { - $isGuarded = $this->jobsCount > 1; + $this->raiseExceptionOccurredJobEvent($queueJob, $e); - $this->raiseExceptionOccurredJobEvent($queueJob, $e); + $queueJob->fail($e); - $queueJob->fail($e); - - throw $e; - } + throw $e; } /** diff --git a/tests/Integration/Queue/JobChainingTest.php b/tests/Integration/Queue/JobChainingTest.php index 382211e4ed4d..b0ad447768f3 100644 --- a/tests/Integration/Queue/JobChainingTest.php +++ b/tests/Integration/Queue/JobChainingTest.php @@ -12,7 +12,7 @@ class JobChainingTest extends TestCase { - public static $catchCallbackCount = 0; + public static $catchCallbackRan = false; protected function getEnvironmentSetUp($app) { @@ -30,6 +30,7 @@ protected function tearDown(): void JobChainingTestFirstJob::$ran = false; JobChainingTestSecondJob::$ran = false; JobChainingTestThirdJob::$ran = false; + static::$catchCallbackRan = false; } public function testJobsCanBeChainedOnSuccess() @@ -147,56 +148,19 @@ public function testThirdJobIsNotFiredIfSecondFails() public function testCatchCallbackIsCalledOnFailure() { - self::$catchCallbackCount = 0; - Bus::chain([ new JobChainingTestFirstJob, new JobChainingTestFailingJob, new JobChainingTestSecondJob, ])->catch(static function () { - self::$catchCallbackCount++; + self::$catchCallbackRan = true; })->dispatch(); $this->assertTrue(JobChainingTestFirstJob::$ran); - $this->assertSame(1, static::$catchCallbackCount); + $this->assertTrue(static::$catchCallbackRan); $this->assertFalse(JobChainingTestSecondJob::$ran); } - public function testCatchCallbackIsCalledOnceOnSyncQueue() - { - self::$catchCallbackCount = 0; - - try { - Bus::chain([ - new JobChainingTestFirstJob(), - new JobChainingTestThrowJob(), - new JobChainingTestSecondJob(), - ])->catch(function () { - self::$catchCallbackCount++; - })->onConnection('sync')->dispatch(); - } finally { - $this->assertTrue(JobChainingTestFirstJob::$ran); - $this->assertSame(1, static::$catchCallbackCount); - $this->assertFalse(JobChainingTestSecondJob::$ran); - } - - self::$catchCallbackCount = 0; - - try { - Bus::chain([ - new JobChainingTestFirstJob(), - new JobChainingTestThrowJob(), - new JobChainingTestSecondJob(), - ])->catch(function () { - self::$catchCallbackCount++; - })->onConnection('sync')->dispatch(); - } finally { - $this->assertTrue(JobChainingTestFirstJob::$ran); - $this->assertSame(1, static::$catchCallbackCount); - $this->assertFalse(JobChainingTestSecondJob::$ran); - } - } - public function testChainJobsUseSameConfig() { JobChainingTestFirstJob::dispatch()->allOnQueue('some_queue')->allOnConnection('sync1')->chain([ @@ -329,13 +293,3 @@ public function handle() $this->fail(); } } - -class JobChainingTestThrowJob implements ShouldQueue -{ - use Dispatchable, InteractsWithQueue, Queueable; - - public function handle() - { - throw new \Exception(); - } -}