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

Added SkipsAfterImportJob Concern

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

Please take note of our contributing guidelines: https://docs.laravel-excel.com/3.1/getting-started/contributing.html Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.

1️⃣ Why should it be added? What are the benefits of this change? ☑️ Excel file in remote (s3) location gets deleted before every queue chunk is processed while using ShouldQueueWithoutChain concern as it is not possible to be sure a specific job executes last. Therefore adding SkipsAfterImport job concern completely eliminates the AfterImportJob, thus file is not deleted. (solving #3560) 2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out. No 3️⃣ Does it include tests, if possible? No 4️⃣ Any drawbacks? Possible breaking changes? No 5️⃣ Mark the following tasks as done:

  • [✅] Checked the codebase to ensure that your feature doesn't already exist.
  • [✅] Take note of the contributing guidelines.
  • [✅] Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • [❌] Added tests to ensure against regression.
  • [✅] Updated the changelog

6️⃣ Thanks for contributing! 🙌

mahdi29 avatar Jun 09 '22 09:06 mahdi29

As mentioned in #3560 I would be okay with a SkipsCleanup. Skipping the entire after import job, also removes the benefit of being able to use the event system.

patrickbrouwers avatar Jun 09 '22 13:06 patrickbrouwers

Job batching seems to be the answer, but this is only available in Laravel 8+ and requires a migration. Then delaycleanup, ShouldQueueWithoutChain etc. is not needed as AfterImport can be set to run after all jobs are processed.

eg having something like this in the ChunkReader should work;

        if ($import instanceof ShouldBatch) {
            return Bus::batch($jobs)
                ->then(function(Batch $batch) use ($afterImportJob, $queue) {
                    dispatch($afterImportJob)->onQueue($queue);
                })->onQueue($queue)->dispatch();
        }

Happy to help with a PR, just not sure if the requirements are too high?

PS: I've not actually experienced the issue of the file being deleted when running jobs without a chain, it seems to run AfterImportJob at the time specified. But it can be a pain waiting for a fixed amount of time.

kchoppin avatar Jun 24 '22 00:06 kchoppin

Besides that batches indeed aren't supported by <8, it also has its own set of issues that I need to carefully consider when adding it to the package; as I've mentioned in a few other tickets as well, that's something I will have a closer look at when going for the 4.0 release.

patrickbrouwers avatar Jun 24 '22 09:06 patrickbrouwers

This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.

stale[bot] avatar Sep 01 '22 05:09 stale[bot]