与PHP的批处理过程分离 - Laravel批处理

发布于 2025-02-06 16:00:21 字数 691 浏览 3 评论 0原文

我有一个程序一次处理几个导入文件。问题是在1分钟之后,网关时间耗尽并杀死流程。为了解决这个问题,我正在使用批处理。它创建了批处理,唯一的问题是我不能从批处理中分离,然后返回浏览器“批处理开始”。这是我启动批处理的代码:

            $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";

代码启动,我可以看到它在数据库中的MySQL Job_batches表中运行并观看更新。直到批处理过程完成后,它才能达到返回语句。因此,持续5分钟的导入后,门户在1分钟后会熄灭,并且无法向前前进。如果我可以让它下车并真正在后台运行,我会做的,因为我可以返回批处理ID并让浏览器调用另一个端点以监视批处理,返回结果等

...帮助您可以为此提供借口。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文