So it works if you use less than a 100 rows? The chunk size
Jan 5, 2022
9
Level 5
The script tried to call a method on an incomplete object
I have an excel file containing 8K products I'm using package Laravel-excel when I upload the file just 1K of products being uploaded and then I got this error in jobs_faild table:
Error: The script tried to call a method on an incomplete object.
Please ensure that the class definition "App\Imports\ImportProducts"
of the object you are trying to operate on was loaded _before_ unserialize()
gets called or provide an autoloader to load the class definition in /var/app/current/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php:107
Stack trace:
#0 /var/app/current/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php(107): method_exists(Object(__PHP_Incomplete_Class), 'middleware')
#1 /var/app/current/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(117): Maatwebsite\Excel\Jobs\ReadChunk->middleware()
My controller to upload the file:
public function updateOrCreateProduct(Request $request)
{
$request->validate([
'file' => 'required|file|mimes:xlsx,csv'
]);
(new ImportProducts)->queue($request->file);
return $this->apiRespone(success: "product updated");
}
ImportProducts file contains:
class ImportProducts implements
ToCollection,
WithChunkReading,
ShouldQueue,
WithEvents,
SkipsEmptyRows,
WithHeadingRow
{
use Importable, RegistersEventListeners;
public function collection(Collection $rows)
{
foreach ($rows as $row) {
// my logic to store data to products table
}
}
public function chunkSize(): int
{
return 100;
}
}
Level 5
I solve the problem! I'm using AWS SQS for the queue, for some reason I just delete the old one and create a new one the queue returns to work perfectly!
Please or to participate in this conversation.