Flask Heroku 超时 - gunicorn 设置更改但仍出现应用程序错误

时间:2021-01-15 12:09:12

标签: flask heroku gunicorn

我创建了一个 Flask 应用程序并将其部署在 heroku 上。我有一个 POST http 请求需要的时间超过标准 30 秒,heroku 在获取超时请求错误之前允许该请求。

为了解决这个问题,我在 Procfile 中更改了我的 gunicorn 设置,如下所示:

web: gunicorn app:app --timeout 10000

Heroku 仍然传达超时错误:

2021-01-15T11:38:25.244638+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/zabiegi_algo/5bf25e5a-6240-eb11-bf69-000d3a2d53fb" host=holmed.herokuapp.com request_id=6f65e74d-9801-48cd-a768-55174d550678 fwd="89.64.65.71" dyno=web.1 connect=2ms service=30000ms status=503 bytes=0 protocol=https

application error

但是,该功能继续运行。函数完成后,我在 heroku 日志中看到以下消息,但是,我没有重定向到所需的 url。

2021-01-15T11:39:33.522779+00:00 app[web.1]: 10.38.217.233 - - [15/Jan/2021:11:39:33 +0000] "GET /zabiegi_algo/5bf25e5a-6240-eb11-bf69-000d3a2d53fb HTTP/1.1" 302 293 "https://holmed.herokuapp.com/zus" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"

这里是带有引起超时请求的函数的路由的具体代码:

@app.route("/zabiegi_algo/<parameter>", methods=['POST'])
def zabiegi_algo(parameter):
    selected_start = '2021-01-01'
    selected_end = '2021-01-31'
    kos_display = 'none'
    done_display = 'none'
    try:
        plan_kos(parameter)
    except KeyError:
        return "<h1 align='center'> Wystapił błąd.</h1>"
    return redirect(f'/karta/{parameter}')

该功能基本上需要大约一分钟才能完成。

我该如何解决这个问题,才不会出现超时错误?我知道可以覆盖 Heroku 默认的 30 秒限制。正确的做法是什么?

0 个答案:

没有答案