F
Filamentβ€’6mo ago
Patrick1989

CSV import job is not executed

I've made an importer:
<?php

namespace App\Filament\Imports;

use App\Models\Invitee;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;

class InviteeImporter extends Importer
{
protected static ?string $model = Invitee::class;
// etc
<?php

namespace App\Filament\Imports;

use App\Models\Invitee;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;

class InviteeImporter extends Importer
{
protected static ?string $model = Invitee::class;
// etc
Now i added this import button to a relationmanager (Invitee) When clicking the button, the modal appears, i can map my fields and then i get the noficiation that the Job is running on the background. I have my queue_driver on SYNC, so that it should run directly. After digging a little deeper, i found the trait that dispatches the job and sends the notification to the database.
Starting on line 183
Starting on line 183

$importChunkIterator = new ChunkIterator($csvResults->getRecords(), chunkSize: $action->getChunkSize()); /** @var array<array<array<string, string>>> $importChunks */ $importChunks = $importChunkIterator->get(); $job = $action->getJob(); $options = array_merge( $action->getOptions(), Arr::except($data, ['file', 'columnMap']), ); $importJobs = collect($importChunks) ->map(fn (array $importChunk): object => new ($job)( $import, rows: $importChunk, columnMap: $data['columnMap'], options: $options, )); Bus::batch($importJobs->all())
```$importJob->all()
```$importJob->all()
is always empty for some reason. The imports table in the database recieves the records, they are there. I'm not sure where to look now. Any idea's?
14 Replies
Patrick1989
Patrick1989β€’6mo ago
the method in the trait recieves the data, its the correct file and mapping
No description
toeknee
toekneeβ€’6mo ago
Do you have the worker running in the background...
Patrick1989
Patrick1989β€’6mo ago
no, i have the queue driver on sync it's not fetching any jobs to dispatch Still haven't been able to figure this one out 😦 added some dd's in that trait:
/** @var array<array<array<string, string>>> $importChunks */
$importChunks = $importChunkIterator->get();


$job = $action->getJob();

$options = array_merge(
$action->getOptions(),
Arr::except($data, ['file', 'columnMap']),
);

$importJobs = collect($importChunks)
->map(fn (array $importChunk): object => new ($job)(
$import,
rows: $importChunk,
columnMap: $data['columnMap'],
options: $options,
));

dd($importJobs, $importChunks, $job, $csvResults->getRecords(), $import);
/** @var array<array<array<string, string>>> $importChunks */
$importChunks = $importChunkIterator->get();


$job = $action->getJob();

$options = array_merge(
$action->getOptions(),
Arr::except($data, ['file', 'columnMap']),
);

$importJobs = collect($importChunks)
->map(fn (array $importChunk): object => new ($job)(
$import,
rows: $importChunk,
columnMap: $data['columnMap'],
options: $options,
));

dd($importJobs, $importChunks, $job, $csvResults->getRecords(), $import);
Patrick1989
Patrick1989β€’6mo ago
No description
Patrick1989
Patrick1989β€’6mo ago
Not sure but i find the $importChunks dd() output a bit strange
Patrick1989
Patrick1989β€’6mo ago
that returns this
No description
bakriawad
bakriawadβ€’6mo ago
how do you get that to work? Having same issue, DB shows always pending, not sure what worker I need to start and where
toeknee
toekneeβ€’6mo ago
php artisan queue:work
bakriawad
bakriawadβ€’6mo ago
is it even possible to bypass the queue and just have direct call to the importer? Documentation isn't saying anything about that
Patrick1989
Patrick1989β€’6mo ago
yea if you ahve the queue_driver on sync it should do it directly but that doesnt work for me either with the imports πŸ˜›
bakriawad
bakriawadβ€’6mo ago
I can't find the queue_driver
Patrick1989
Patrick1989β€’6mo ago
add it to your env file QUEUE_DRIVER=sync or you can change it in config/queue.php it should resort to sync by default
bakriawad
bakriawadβ€’6mo ago
thanks! well, it seems it already was in sync... yet that never worked. Another weird thing is, php artisan queue:work worked initially for me, then I deleted all records in the queue and created new ones, but now it doesn't recognize the new jobs and doesn't fire anymore
Patrick1989
Patrick1989β€’6mo ago
i have no problems running other jobs tho, its just the csv imports that dont work ill try it with a fresh install this weekend, ill let you know if i find something