Laravel-Excel icon indicating copy to clipboard operation
Laravel-Excel copied to clipboard

[Bug]: File gets deleted after first chunk while using ShouldQueueWithoutChain

Open mahdi29 opened this issue 3 years ago • 9 comments
trafficstars

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

  • [x] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.36

What version of Laravel are you using?

8.12

What version of PHP are you using?

8.1

Describe your issue

Excel file in remote (s3) location gets deleted after first queue chunk is processed while using ShouldQueueWithoutChain concern

Therefore showing following error while processing other queue chunk.

File not found at path: tmp/laravel-excel-xxxxxxxx.xlsx

What should be the expected behaviour?

The file should stay until the last queue is processed and then deleted

Or there should be option to keep the file and not delete, we can always delete is using schedule.

mahdi29 avatar Feb 28 '22 10:02 mahdi29

I think the issue is that you using without chain, there's no way for us to know if its the last chunk or not.

patrickbrouwers avatar Feb 28 '22 11:02 patrickbrouwers

I think the issue is that you using without chain, there's no way for us to know if its the last chunk or not.

Yes, I'm using without chain.

But the problem is "AfterImportJob" is processed first and it removes the tmp file in remote directory (s3).

The delay is also not being considered in $jobs->push($afterImportJob->delay($delayCleanup));

I'm using SQS and S3 on Laravel Vapor

mahdi29 avatar Mar 01 '22 08:03 mahdi29

As I said, without the chain it is not possible to be sure a specific job executes last. Depending on the amount of workers any job could be the first or last

patrickbrouwers avatar Mar 01 '22 09:03 patrickbrouwers

@mahdi29 try setting the the following property in your import class. If you are using vapor 900 seconds is the longest it can wait. This should ensure that cleanup doesn't happen until 10 minutes after the job is finished. Though it's odd yours fires immediately as 10 minutes is the default for this property.

    /**
     * Specify the Cleanup Delay for 10 minutes.
     * @var int
     */
    public int $delayCleanup = 600;

mgratch avatar Mar 04 '22 20:03 mgratch

I forgot we had that option. That should indeed prevent the clean-up of the remote file until 10 minutes later. Perhaps not all queue worker support it? Are you using redis/horizon?

patrickbrouwers avatar Mar 04 '22 21:03 patrickbrouwers

Locally redis/horizon. But Vapor for staging/production.

mgratch avatar Mar 04 '22 21:03 mgratch

@mgratch sorry the question was intended at @mahdi29 haha. Make sense it work on those 2 yes.

patrickbrouwers avatar Mar 04 '22 21:03 patrickbrouwers

@mgratch sorry the question was intended at @mahdi29 haha. Make sense it work on those 2 yes.

I use Vapor and it supports delay. However, after delay (15 min) the AfterImportJob runs and deletes file, but during that time only half of my queue were processed and other half gives "File not found at path" error.

I believe the only solution would be to use SQS FIFO but that's not supported in laravel vapor.

The other solution would be to completely skip AfterImportJob, but I don't find any way to do it.

Having SkipAfterImportJob/SkipFileDelete concern would solve the issue.

mahdi29 avatar Mar 17 '22 09:03 mahdi29

I would be fine with a SkipCleanup concern

patrickbrouwers avatar May 12 '22 14:05 patrickbrouwers

Any plans to address this @patrickbrouwers ? I am hitting the same problem using Bref and SQS.

Sh1d0w avatar Aug 27 '23 00:08 Sh1d0w

Actually the solution is pretty simple, using FIFO after complete job will be processed last. Opened a PR https://github.com/SpartnerNL/Laravel-Excel/pull/3986, thanks

Sh1d0w avatar Aug 28 '23 10:08 Sh1d0w