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

Conversation

BenQoder
Copy link
Contributor

@BenQoder BenQoder commented Nov 7, 2024

The PR adds NonRetryableException.

When this exception is thrown, The Activity will not retry and The Workflow Marks as Fail.

This implementation will work similarly to Cloudflare Workflow NonRetryableError

NonRetryableException

@rmcdaniel
Copy link
Contributor

Sorry for the delay. I have not forgotten about this!

@travisaustin
Copy link

Thank you! This will be a helpful addition to this project.

Would you consider making an interface/contract that can mark any exception class as NonRetryable? That would allow us to make any existing exception class NonRetryable without having to extend the NonRetryable class (which may be difficult if the exception is already extending a different base class).

Here's what it would look like:

NonRetryableException.php:

<?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);
    }
}

NonRetryableExceptionContract.php:

<?php

declare(strict_types=1);

namespace Workflow\Exceptions;

interface NonRetryableExceptionContract {}

In Activity.php, you'd catch the exceptions with:

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

With this change, you can still throw a NonRetryableException to fail an activity. If there are other exceptions in a project that should fail an activity, you can simply add implements NonRetryableExceptionContract to the class definition and that exception will fail an activity, as well.

@BenQoder
Copy link
Contributor Author

@travisaustin This is a really nice suggestion.

I will improve my PR to add that.

@BenQoder
Copy link
Contributor Author

@rmcdaniel It would be really nice if you take out sometime to review this PR?

Thanks a lot

@BenQoder
Copy link
Contributor Author

BenQoder commented Jan 6, 2025

@rmcdaniel
Do you think I should close this PR?
Because it's been open for so long now.

@rmcdaniel
Copy link
Contributor

I'm going to try to get to it this week. I will also be pushing out a new release. Thank you for your patience!

@rmcdaniel rmcdaniel merged commit b1d8343 into laravel-workflow:master Jan 9, 2025
2 checks passed
@rmcdaniel
Copy link
Contributor

@BenQoder Hey there, as promised I have merged this, published a new release and I have also updated the documentation at https://laravel-workflow.com/docs/failures-and-recovery/#non-retryable-exceptions

Thanks for your contribution! 🙌

@BenQoder
Copy link
Contributor Author

It's cool... 👍🏾

Finally I can stop using my fork and change to the updated version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
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