I developed an open-source faceless video automation service using Laravel (code included!)

In this video I'll be going over the open-source faceless automation tool I created using Laravel & Remotion.

This open-source faceless video automation service has its roots in my commercial project VideoMat.

Sending a PR to the Laravel framework

During development of this project, I stumbled upon an issue in the Laravel framework. When creating and dispatching a chain with a nested batch, the type of the batch will be a ChainedBatch

\Illuminate\Support\Facades\Bus::chain([
    Bus::batch([
        new \App\Jobs\HelloWorld(),
    ])
])->dispatch();

However, when appending or prepending a batch to a chain, the type will be a PendingBatch, leading to serialization errors.

\Illuminate\Support\Facades\Bus::chain([
    new \App\Jobs\Batcher(),
])->dispatch();

// App\Jobs\Batcher()

<?php

namespace App\Jobs;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Bus;

class Batcher implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new job instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        // The type of this batch will be PendingBatch, leading to errors
        $this->prependToChain(
            Bus::batch([
                new \App\Jobs\HelloWorld(),
            ])
        );
    }
}

To mitigate this, I opened the following PR in the Laravel framework:

Run prepareNestedBatches on append/prependToChain & chain by SabatinoMasala · Pull Request #52486 · laravel/framework
The issue with appending/prepending a batch from within a job Currently, when appending or prepending a batch from within a job, you get the following error: Serialization of &#39;Closure&#39; is n…

And it got approved 🎉

Starting from Laravel 11.21.0 it's now possible to append/prepend batches to a chain from within a job.

Links

Subscribe to sabatino.dev

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe