Skip to content

Commit f346e95

Browse files
authored
Revert "[8.x] Prevent double throwing chained exception on sync queue (#42950)" (#43354)
This reverts commit 41300c6.
1 parent 49c2163 commit f346e95

File tree

2 files changed

+7
-67
lines changed

2 files changed

+7
-67
lines changed

src/Illuminate/Queue/SyncQueue.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
class SyncQueue extends Queue implements QueueContract
1414
{
15-
protected $jobsCount = 0;
16-
1715
/**
1816
* Get the size of the queue.
1917
*
@@ -39,8 +37,6 @@ public function push($job, $data = '', $queue = null)
3937
{
4038
$queueJob = $this->resolveJob($this->createPayload($job, $queue, $data), $queue);
4139

42-
$this->jobsCount++;
43-
4440
try {
4541
$this->raiseBeforeJobEvent($queueJob);
4642

@@ -49,8 +45,6 @@ public function push($job, $data = '', $queue = null)
4945
$this->raiseAfterJobEvent($queueJob);
5046
} catch (Throwable $e) {
5147
$this->handleException($queueJob, $e);
52-
} finally {
53-
$this->jobsCount--;
5448
}
5549

5650
return 0;
@@ -119,19 +113,11 @@ protected function raiseExceptionOccurredJobEvent(Job $job, Throwable $e)
119113
*/
120114
protected function handleException(Job $queueJob, Throwable $e)
121115
{
122-
static $isGuarded = false;
123-
124-
if ($isGuarded) {
125-
$isGuarded = false;
126-
} else {
127-
$isGuarded = $this->jobsCount > 1;
116+
$this->raiseExceptionOccurredJobEvent($queueJob, $e);
128117

129-
$this->raiseExceptionOccurredJobEvent($queueJob, $e);
118+
$queueJob->fail($e);
130119

131-
$queueJob->fail($e);
132-
133-
throw $e;
134-
}
120+
throw $e;
135121
}
136122

137123
/**

tests/Integration/Queue/JobChainingTest.php

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class JobChainingTest extends TestCase
1414
{
15-
public static $catchCallbackCount = 0;
15+
public static $catchCallbackRan = false;
1616

1717
protected function getEnvironmentSetUp($app)
1818
{
@@ -30,6 +30,7 @@ protected function tearDown(): void
3030
JobChainingTestFirstJob::$ran = false;
3131
JobChainingTestSecondJob::$ran = false;
3232
JobChainingTestThirdJob::$ran = false;
33+
static::$catchCallbackRan = false;
3334
}
3435

3536
public function testJobsCanBeChainedOnSuccess()
@@ -147,56 +148,19 @@ public function testThirdJobIsNotFiredIfSecondFails()
147148

148149
public function testCatchCallbackIsCalledOnFailure()
149150
{
150-
self::$catchCallbackCount = 0;
151-
152151
Bus::chain([
153152
new JobChainingTestFirstJob,
154153
new JobChainingTestFailingJob,
155154
new JobChainingTestSecondJob,
156155
])->catch(static function () {
157-
self::$catchCallbackCount++;
156+
self::$catchCallbackRan = true;
158157
})->dispatch();
159158

160159
$this->assertTrue(JobChainingTestFirstJob::$ran);
161-
$this->assertSame(1, static::$catchCallbackCount);
160+
$this->assertTrue(static::$catchCallbackRan);
162161
$this->assertFalse(JobChainingTestSecondJob::$ran);
163162
}
164163

165-
public function testCatchCallbackIsCalledOnceOnSyncQueue()
166-
{
167-
self::$catchCallbackCount = 0;
168-
169-
try {
170-
Bus::chain([
171-
new JobChainingTestFirstJob(),
172-
new JobChainingTestThrowJob(),
173-
new JobChainingTestSecondJob(),
174-
])->catch(function () {
175-
self::$catchCallbackCount++;
176-
})->onConnection('sync')->dispatch();
177-
} finally {
178-
$this->assertTrue(JobChainingTestFirstJob::$ran);
179-
$this->assertSame(1, static::$catchCallbackCount);
180-
$this->assertFalse(JobChainingTestSecondJob::$ran);
181-
}
182-
183-
self::$catchCallbackCount = 0;
184-
185-
try {
186-
Bus::chain([
187-
new JobChainingTestFirstJob(),
188-
new JobChainingTestThrowJob(),
189-
new JobChainingTestSecondJob(),
190-
])->catch(function () {
191-
self::$catchCallbackCount++;
192-
})->onConnection('sync')->dispatch();
193-
} finally {
194-
$this->assertTrue(JobChainingTestFirstJob::$ran);
195-
$this->assertSame(1, static::$catchCallbackCount);
196-
$this->assertFalse(JobChainingTestSecondJob::$ran);
197-
}
198-
}
199-
200164
public function testChainJobsUseSameConfig()
201165
{
202166
JobChainingTestFirstJob::dispatch()->allOnQueue('some_queue')->allOnConnection('sync1')->chain([
@@ -329,13 +293,3 @@ public function handle()
329293
$this->fail();
330294
}
331295
}
332-
333-
class JobChainingTestThrowJob implements ShouldQueue
334-
{
335-
use Dispatchable, InteractsWithQueue, Queueable;
336-
337-
public function handle()
338-
{
339-
throw new \Exception();
340-
}
341-
}

0 commit comments

Comments
 (0)