You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
$this->prependToChain(
Bus::batch([
new \App\Jobs\HelloWorld(),
])
);
}
}
To mitigate this, you can manually create a ChainedBatch from the PendingBatch as follows:
$chainedBatch = new ChainedBatch(Bus::batch([
new HelloWorld(),
]));
$this->prependToChain($chainedBatch);
And this will make sure the batch gets queued onto the chain correctly.
Steps To Reproduce
Dispatching a batch onto a chain from within a job using prependToChain or appendToChain will result into a closure serialization error.
The text was updated successfully, but these errors were encountered:
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Laravel Version
11.20.0
PHP Version
8.2
Database Driver & Version
No response
Description
When creating and dispatching a chain with a nested batch, the type of the batch will be a
ChainedBatch
However, when appending or prepending a batch to a chain, the type will be a
PendingBatch
, leading to serialization errors.To mitigate this, you can manually create a ChainedBatch from the PendingBatch as follows:
And this will make sure the batch gets queued onto the chain correctly.
Steps To Reproduce
Dispatching a batch onto a chain from within a job using
prependToChain
orappendToChain
will result into a closure serialization error.The text was updated successfully, but these errors were encountered: