diff --git a/src/Activity.php b/src/Activity.php index bb230e0..3958bdf 100644 --- a/src/Activity.php +++ b/src/Activity.php @@ -18,6 +18,7 @@ use LimitIterator; use SplFileObject; use Throwable; +use Workflow\Exceptions\NonRetryableExceptionContract; use Workflow\Middleware\ActivityMiddleware; use Workflow\Middleware\WithoutOverlappingMiddleware; use Workflow\Models\StoredWorkflow; @@ -93,6 +94,10 @@ public function handle() 'exception' => Y::serialize($throwable), ]); + if ($throwable instanceof NonRetryableExceptionContract) { + $this->fail($throwable); + } + throw $throwable; } } diff --git a/src/Exceptions/NonRetryableException.php b/src/Exceptions/NonRetryableException.php new file mode 100644 index 0000000..21d7ce0 --- /dev/null +++ b/src/Exceptions/NonRetryableException.php @@ -0,0 +1,16 @@ +assertSame('failed', Y::unserialize($workflow->exceptions()->first()->exception)['message']); } } + + public function testNonRetryableException(): void + { + $workflow = WorkflowStub::make(NonRetryableTestExceptionWorkflow::class); + + $workflow->start(); + + while ($workflow->running()); + + $this->assertSame(WorkflowFailedStatus::class, $workflow->status()); + $this->assertNotNull($workflow->exceptions()->first()); + $this->assertNull($workflow->output()); + $this->assertSame( + 'This is a non-retryable error', + Y::unserialize($workflow->exceptions()->last()->exception)['message'] + ); + } } diff --git a/tests/Fixtures/NonRetryableTestExceptionActivity.php b/tests/Fixtures/NonRetryableTestExceptionActivity.php new file mode 100644 index 0000000..b6b1692 --- /dev/null +++ b/tests/Fixtures/NonRetryableTestExceptionActivity.php @@ -0,0 +1,16 @@ +
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: