Manage Job Workflows with Venture

Packages

October 16th, 2020

venture-featured.png

Venture is a package to help you build and manage complex, asynchronous workflows in your Laravel applications. Here’s an example from the documentation which illustrates a workflow defined when publishing a podcast:

Workflow::new('Publish new podcast')
    ->addJob(new ProcessPodcast($podcast))
    ->addJob(new OptimizePodcast($podcast))
    ->addJob(new PublishPodcastOnTransistorFM($podcast), [
        ProcessPodcast::class,
        OptimizePodcast::class
    ]);

In the above example, publishing the podcast depends on the processing and optimization of job completion.

At the heart of this package is the WorkflowStep trait that you’ll need to add to jobs to use them within a workflow. This trait enables Venture to track a job’s dependencies and other dependent jobs.

Another neat feature is performing an action after a workflow has finished:

Workflow::new('Example Workflow')
    ->addJob(new ExampleJob())
    ->then(function (Workflow $workflow) {
        // This will get called once every job in the workflow has finished.
        // It gets passed the workflow instance.
    })
    ->start();

// You can also use an invokable class with the `then()` method.
class SendNotification
{
    public function __invokable(Workflow $workflow)
    {
        // Do something with the workflow...
    }
}

Workflow::new('Example Workflow')
    ->addJob(new ExampleJob())
    ->then(new SendNotification())
    ->start();

Venture also helps you deal with failures in a workflow, failed steps, and things like canceling the workflow. You can learn more about this package, get full installation instructions, and view the source code on GitHub at ksassnowski/venture.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.