# Dealing with errors

# Failures inside a workflow

To explain how failed jobs affect a workflow, let's take a look at the following example:

In the workflow above, JobB failed to execute successfully. This will prevent all jobs in that subtree of the workflow from running. In this case JobB failing will prevent JobC, JobD and JobE from executing, since each of them either has a direct dependency or transitive dependency on it.

It will, however, not affect the execution of JobF and JobG because neither of them have any dependency on JobB.

This is a powerful property of workflows as it makes them more robust and less all-or-nothing. Just because you failed to notify your subscribers about a new podcast does not mean that the job to generate a transcription should not be run.

If you do want a workflow to stop executing any further jobs, check the section below about cancelling a workflow.

# Handling failed steps

Venture tries to provide a familiar API if you're used to Laravel's queue batching feature(opens new window) . As such, you can register a catch callback when defining your workflow.

Workflow::define('Register Podcast')
    ->catch(function (Workflow $workflow, $job, Throwable $e) {

This callback will be called any time one of the jobs in the workflow is marked as failed.

Watch out

When designing your catch callback, be aware that it might be called multiple times if multiple jobs fail.

# Cancelling a workflow

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. This can be useful if you want to display a Cancel Workflow button in your UI for example.


Workflow::define('Register Podcast')
    ->catch(function (Workflow $workflow, $job, Throwable $e) {

A cancelled workflow will not execute any further jobs. It does not affect jobs that have already run or jobs that were already processing when the workflow was cancelled.

Cancelling an already cancelled job

The cancel method of a workflow is idempotent(opens new window) , meaning you can safely call it multiple times without updating the timestamp everytime. It will remain the date the workflow was first cancelled.