Skip to content

Added NonRetryableException #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +94,10 @@ public function handle()
'exception' => Y::serialize($throwable),
]);

if ($throwable instanceof NonRetryableExceptionContract) {
$this->fail($throwable);
}

throw $throwable;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/Exceptions/NonRetryableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Workflow\Exceptions;

use Exception;
use Throwable;

class NonRetryableException extends Exception implements NonRetryableExceptionContract
{
public function __construct($message = '', $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
9 changes: 9 additions & 0 deletions src/Exceptions/NonRetryableExceptionContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Workflow\Exceptions;

interface NonRetryableExceptionContract
{
}
19 changes: 19 additions & 0 deletions tests/Feature/ExceptionWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Tests\Feature;

use Tests\Fixtures\NonRetryableTestExceptionWorkflow;
use Tests\Fixtures\TestExceptionWorkflow;
use Tests\TestCase;
use Workflow\Serializers\Y;
use Workflow\States\WorkflowCompletedStatus;
use Workflow\States\WorkflowFailedStatus;
use Workflow\WorkflowStub;

final class ExceptionWorkflowTest extends TestCase
Expand All @@ -26,4 +28,21 @@ public function testRetry(): void
$this->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']
);
}
}
16 changes: 16 additions & 0 deletions tests/Fixtures/NonRetryableTestExceptionActivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures;

use Workflow\Activity;
use Workflow\Exceptions\NonRetryableException;

final class NonRetryableTestExceptionActivity extends Activity
{
public function execute()
{
throw new NonRetryableException('This is a non-retryable error');
}
}
19 changes: 19 additions & 0 deletions tests/Fixtures/NonRetryableTestExceptionWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures;

use Workflow\ActivityStub;
use Workflow\Workflow;

final class NonRetryableTestExceptionWorkflow extends Workflow
{
public function execute()
{
yield ActivityStub::make(NonRetryableTestExceptionActivity::class);
yield ActivityStub::make(TestActivity::class);

return 'Workflow completes';
}
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy