Skip to content
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

Documentation: Clarification on how to cancel a workflow #101

Open
eznix86 opened this issue Aug 9, 2024 · 2 comments
Open

Documentation: Clarification on how to cancel a workflow #101

eznix86 opened this issue Aug 9, 2024 · 2 comments

Comments

@eznix86
Copy link

eznix86 commented Aug 9, 2024

I have to read the code to figure out how to cancel a workflow. Maybe you can clarify it or add it to the docs.

What I Understand so far is whenever you use this trait: WorkflowStep. You have the possibility of having the Workflow object which can be canceled.

<?php

namespace App\Jobs;

use Sassnowski\Venture\WorkflowStep;
use Illuminate\Contracts\Queue\ShouldQueue;

class MyJob implements ShouldQueue
{
    use WorkflowStep;
    
    // ... somewhere when handling the job
    
        $this->workflow()?->cancel(); // this will prevent the workflow from proceeding further 
}

Sources:

public function workflow(): ?Workflow

public function cancel(): void

@eznix86 eznix86 changed the title Documentation: Missing information on how to cancel a workflow Documentation: Clarification on how to cancel a workflow Aug 9, 2024
@ksassnowski
Copy link
Owner

There's a (small) section in the docs about this here: https://laravel-venture.com/usage/dealing-with-errors.html#cancelling-a-workflow

@eznix86
Copy link
Author

eznix86 commented Aug 9, 2024

That's a fast response. Yes I saw that, this is from outside of a job but it does not explicitly say:

You can mark a workflow as cancelled by calling its cancel method [using WorkflowStep trait from the workflow() method]

but you say

You can mark a workflow as cancelled by calling its cancel method. This is usually going to happen inside the workflow's catch callback, but there's nothing stopping you from fetching a workflow from the database and calling its cancel function there.

So do you confirm we can use WorkflowStep trait within a job to prevent the workflow to continue ?

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

No branches or pull requests

2 participants