Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ReadChunk Job Still runs when all excel rows have been imported #4205

Open
1 task done
codenesiareborn opened this issue Sep 17, 2024 · 3 comments
Open
1 task done
Labels

Comments

@codenesiareborn
Copy link

codenesiareborn commented Sep 17, 2024

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.30

What version of Laravel are you using?

9.19

What version of PHP are you using?

8.2.0

Describe your issue

Maatwebsite\Excel\Jobs\ReadChunk still runs when all excel rows have been imported

Screenshot 2024-09-18 at 2 07 31 AM

How can the issue be reproduced?

`class BulkConnectExcelImport implements WithMultipleSheets, ShouldQueue, WithChunkReading
{

public function sheets(): array
{
    return [
        'Daftar Daerah' => new DaftarDaerahSheet(),
        'Connect' => new ConnectSheet(),
    ];
}

public function registerEvents(): array
{
    return [
        // Triggered after a successful import
        AfterImport::class => function(AfterImport $event) {
            Log::info('selesai impor');
            session()->flash('success', 'Import completed successfully!');
        },

        // Triggered if the import fails
        ImportFailed::class => function(ImportFailed $event) {
            Log::info('tidak selesai impor');

            session()->flash('error', 'The import failed: ' . $event->getException()->getMessage());
        },
    ];
}

public function failed(\Exception $exception)
{
    // Handle failure (log error, notify user, etc.)
    session()->flash('error', 'Job failed: ' . $exception->getMessage());
}

public function chunkSize(): int
{
    return 500;
}

}`

What should be the expected behaviour?

the job should stop when all rows are successfully uploaded

@POWRFULCOW89
Copy link

I'm facing this issue too in Laravel Excel 3.1.55, using Laravel 9.52 and PHP 8.3.8:

class TestImport implements ToArray, WithStartRow, SkipsEmptyRows, WithMultipleSheets, WithChunkReading, ShouldQueue
{
    public function __construct(private readonly User $user)
    {
    }

    public function array(array $array): void
    {
        foreach ($array as $index => $row) {
            ProcessExcelQuote::dispatch($row, $this->user, $index);
        }
    }

    public function sheets(): array
    {
        return [
            '0' => $this
        ];
    }

    public function startRow(): int
    {
        return 3;
    }

    public function chunkSize(): int
    {
        return 10;
    }
}

After reading a sheet with 3 rows it keeps on reading:


2024-09-17 18:14:54 Maatwebsite\Excel\Jobs\QueueImport ................................................................................................................................................................................................................................................. RUNNING
  2024-09-17 18:14:54 Maatwebsite\Excel\Jobs\QueueImport ........................................................................................................................................................................................................................................... 158.79ms DONE
  2024-09-17 18:14:54 Maatwebsite\Excel\Jobs\ReadChunk ................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:14:55 Maatwebsite\Excel\Jobs\ReadChunk ............................................................................................................................................................................................................................................. 508.37ms DONE
  2024-09-17 18:14:55 App\Jobs\ProcessExcelQuote ......................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:14:57 App\Jobs\ProcessExcelQuote ................................................................................................................................................................................................................................................. 2,091.42ms FAIL
  2024-09-17 18:14:57 App\Jobs\ProcessExcelQuote ......................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:14:58 App\Jobs\ProcessExcelQuote ................................................................................................................................................................................................................................................. 1,349.21ms FAIL
  2024-09-17 18:14:58 App\Jobs\ProcessExcelQuote ......................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:15:00 App\Jobs\ProcessExcelQuote ................................................................................................................................................................................................................................................. 1,696.43ms FAIL
  2024-09-17 18:15:00 Maatwebsite\Excel\Jobs\ReadChunk ................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:15:01 Maatwebsite\Excel\Jobs\ReadChunk ............................................................................................................................................................................................................................................. 422.58ms DONE
  2024-09-17 18:15:01 Maatwebsite\Excel\Jobs\ReadChunk ................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:15:01 Maatwebsite\Excel\Jobs\ReadChunk ............................................................................................................................................................................................................................................. 399.25ms DONE

I believe it might have something to do with having created the .xlsx file from Google Sheets, which seems to append a bunch of rows at the end of the sheet

@codenesiareborn
Copy link
Author

I'm facing this issue too in Laravel Excel 3.1.55, using Laravel 9.52 and PHP 8.3.8:

class TestImport implements ToArray, WithStartRow, SkipsEmptyRows, WithMultipleSheets, WithChunkReading, ShouldQueue
{
    public function __construct(private readonly User $user)
    {
    }

    public function array(array $array): void
    {
        foreach ($array as $index => $row) {
            ProcessExcelQuote::dispatch($row, $this->user, $index);
        }
    }

    public function sheets(): array
    {
        return [
            '0' => $this
        ];
    }

    public function startRow(): int
    {
        return 3;
    }

    public function chunkSize(): int
    {
        return 10;
    }
}

After reading a sheet with 3 rows it keeps on reading:


2024-09-17 18:14:54 Maatwebsite\Excel\Jobs\QueueImport ................................................................................................................................................................................................................................................. RUNNING
  2024-09-17 18:14:54 Maatwebsite\Excel\Jobs\QueueImport ........................................................................................................................................................................................................................................... 158.79ms DONE
  2024-09-17 18:14:54 Maatwebsite\Excel\Jobs\ReadChunk ................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:14:55 Maatwebsite\Excel\Jobs\ReadChunk ............................................................................................................................................................................................................................................. 508.37ms DONE
  2024-09-17 18:14:55 App\Jobs\ProcessExcelQuote ......................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:14:57 App\Jobs\ProcessExcelQuote ................................................................................................................................................................................................................................................. 2,091.42ms FAIL
  2024-09-17 18:14:57 App\Jobs\ProcessExcelQuote ......................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:14:58 App\Jobs\ProcessExcelQuote ................................................................................................................................................................................................................................................. 1,349.21ms FAIL
  2024-09-17 18:14:58 App\Jobs\ProcessExcelQuote ......................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:15:00 App\Jobs\ProcessExcelQuote ................................................................................................................................................................................................................................................. 1,696.43ms FAIL
  2024-09-17 18:15:00 Maatwebsite\Excel\Jobs\ReadChunk ................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:15:01 Maatwebsite\Excel\Jobs\ReadChunk ............................................................................................................................................................................................................................................. 422.58ms DONE
  2024-09-17 18:15:01 Maatwebsite\Excel\Jobs\ReadChunk ................................................................................................................................................................................................................................................... RUNNING
  2024-09-17 18:15:01 Maatwebsite\Excel\Jobs\ReadChunk ............................................................................................................................................................................................................................................. 399.25ms DONE

I believe it might have something to do with having created the .xlsx file from Google Sheets, which seems to append a bunch of rows at the end of the sheet

how can we skip the empty rows?

@jeff1326
Copy link

jeff1326 commented Sep 25, 2024

I'm facing this issue too in Laravel Excel 3.1.55, using Laravel 11.20.0 and PHP 8.3.11

But it's on a job named ImportTextsTranslations

$import = new TranslationImport();
Excel::import($import, storage_path('app/' . $file));
class TranslationImport implements ToCollection, WithHeadingRow, WithMultipleSheets
{
    // In case of the file having multiple sheets, this method will be called multiple times.
    #[\Override]
    public function collection(Collection $rows)
    {
        // My customer code here
    }

    // Force to ignore other sheets that translator adds that crash the import
    #[\Override]
    public function sheets(): array
    {
        return [
            0 => $this,
        ];
    }
}

image

I got this problem only while importing multiples files.
If i was importing them one by one, i was fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants