F
Filamentβ€’12mo ago
Patrick

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
Patrick
PatrickOPβ€’12mo ago
the method in the trait recieves the data, its the correct file and mapping
No description
toeknee
toekneeβ€’12mo ago
Do you have the worker running in the background...
Patrick
PatrickOPβ€’12mo 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);
Patrick
PatrickOPβ€’12mo ago
No description
Patrick
PatrickOPβ€’12mo ago
Not sure but i find the $importChunks dd() output a bit strange
Patrick
PatrickOPβ€’12mo ago
that returns this
No description
bakriawad
bakriawadβ€’12mo 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β€’12mo ago
php artisan queue:work
bakriawad
bakriawadβ€’12mo ago
is it even possible to bypass the queue and just have direct call to the importer? Documentation isn't saying anything about that
Patrick
PatrickOPβ€’12mo 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β€’12mo ago
I can't find the queue_driver
Patrick
PatrickOPβ€’12mo 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β€’12mo 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
Patrick
PatrickOPβ€’12mo 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
Want results from more Discord servers?
Add your server