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:
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
- Faceless Laravel example: https://github.com/SabatinoMasala/faceless-laravel-example
- Laravel batch bug: https://github.com/SabatinoMasala/laravel-batch-bug