0

I have a program that processes several import files at a time. Problem is after 1 minute the gateway times out and kills the processes. To get around this I am using batching. It creates the batch just fine the only problem is I can't detach from the batch and return back to the browser "Batch Started". Here is my code where I start the batch:

            $files = self::prepare_files($request);

            // Lets batch this call
            $batch = Bus::batch([
                new ImportJob($files),
            ])
            ->then(function (Batch $batch) use($files) {
                //This is not really needed
            })
            ->dispatch();

            return "Batch Started";

The code starts up and I can see it running in the MySQL job_batches table in my database and watch it update. It doesn't hit the return statement until after the batch process finishes running. So with an import that lasts 5 minutes, the gateway times out after 1 minute and it can't move forward. If I can get it to drop off and truly run in the background I would have it made since I can return the batch ID and let the browser call another endpoint to monitor the batch, return results, etc...

Thanks in advance for any help you can lend on this.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 1
    Have you seen [this answer](https://stackoverflow.com/a/4626970/4146962)? Read the note at the end. – Sanxofon Jun 09 '22 at 21:20
  • Interesting. I will have to look at that to see if it will work for my situation. Only issue I see there is that takes it out of the Laravel environment and into the shell environment. That isn't really bad since I can make some command files to be executed within Laravel via the shell prompt. I believe this will work. I just didn't think about this avenue. Thanks for your help. – Michael D. Kirkpatrick Jun 14 '22 at 21:02

0 Answers0