Skip to content

Commit

Permalink
Invoke progress callback also on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
orkhanahmadov committed Dec 7, 2023
1 parent debde5b commit d693b1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Illuminate/Bus/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ public function recordFailedJob(string $jobId, $e)
$this->cancel();
}

if ($this->hasProgressCallbacks() && $this->allowsFailures()) {
$batch = $this->fresh();

collect($this->options['progress'])->each(function ($handler) use ($batch, $e) {
$this->invokeHandlerCallback($handler, $batch, $e);
});
}

if ($counts->failedJobs === 1 && $this->hasCatchCallbacks()) {
$batch = $this->fresh();

Expand Down
2 changes: 2 additions & 0 deletions tests/Bus/BusBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public function test_failed_jobs_can_be_recorded_while_not_allowing_failures()
$this->assertTrue($batch->finished());
$this->assertTrue($batch->cancelled());
$this->assertEquals(1, $_SERVER['__finally.count']);
$this->assertEquals(0, $_SERVER['__progress.count']);
$this->assertEquals(1, $_SERVER['__catch.count']);
$this->assertSame('Something went wrong.', $_SERVER['__catch.exception']->getMessage());
}
Expand Down Expand Up @@ -291,6 +292,7 @@ public function test_failed_jobs_can_be_recorded_while_allowing_failures()
$this->assertFalse($batch->finished());
$this->assertFalse($batch->cancelled());
$this->assertEquals(1, $_SERVER['__catch.count']);
$this->assertEquals(2, $_SERVER['__progress.count']);
$this->assertSame('Something went wrong.', $_SERVER['__catch.exception']->getMessage());
}

Expand Down

0 comments on commit d693b1b

Please sign in to comment.