diff --git a/src/Projection/Projectionist/DefaultProjectionist.php b/src/Projection/Projectionist/DefaultProjectionist.php index 52a334fb0..754ef5bc5 100644 --- a/src/Projection/Projectionist/DefaultProjectionist.php +++ b/src/Projection/Projectionist/DefaultProjectionist.php @@ -94,6 +94,10 @@ public function boot( $e->getMessage(), )); + $projection->error(ProjectionError::fromThrowable($e)); + $projection->disallowRetry(); + $this->projectionStore->save($projection); + if ($throwByError) { throw new ProjectionistError( $projector::class, @@ -101,10 +105,6 @@ public function boot( $e, ); } - - $projection->error(ProjectionError::fromThrowable($e)); - $projection->disallowRetry(); - $this->projectionStore->save($projection); } } @@ -469,6 +469,10 @@ private function handleMessage(Message $message, Projection $projection, bool $t ), ); + $projection->error(ProjectionError::fromThrowable($e)); + $projection->incrementRetry(); + $this->projectionStore->save($projection); + if ($throwByError) { throw new ProjectionistError( $projector::class, @@ -477,10 +481,6 @@ private function handleMessage(Message $message, Projection $projection, bool $t ); } - $projection->error(ProjectionError::fromThrowable($e)); - $projection->incrementRetry(); - $this->projectionStore->save($projection); - return; } diff --git a/src/Projection/Projectionist/SyncProjectionistEventBusWrapper.php b/src/Projection/Projectionist/SyncProjectionistEventBusWrapper.php index 1f89db4fe..66fd37282 100644 --- a/src/Projection/Projectionist/SyncProjectionistEventBusWrapper.php +++ b/src/Projection/Projectionist/SyncProjectionistEventBusWrapper.php @@ -15,6 +15,7 @@ public function __construct( private readonly EventBus $parentEventBus, private readonly Projectionist $projectionist, private readonly LockFactory $lockFactory, + private readonly bool $throwByError = true, ) { } @@ -29,7 +30,7 @@ public function dispatch(Message ...$messages): void } try { - $this->projectionist->run(); + $this->projectionist->run(throwByError: $this->throwByError); } finally { $lock->release(); }