如何解决RQ多个任务H12 HEROKU超时



我正在尝试使用redis运行Heroku烧瓶python应用程序。但是,我面临以下错误:

at=error code=H12 desc="Request timeout" method=POST path="/uploaderlocal" host=a2n.herokuapp.com dyno=web.1 connect=1ms service=31890ms status=503 bytes=0 protocol=https

Heroku网页崩溃了上述错误(由于超时),但是背景过程将继续运行。是否有任何可能的方法可以使Heroku网页失望,直到Redis背景队列完成的任务完成?以下是我的代码供您参考。请注意,在返回结果之前,我试图完成多个重新排队的任务。html模板。

from rq import Queue
from worker import conn
from rq.job import Job
app = Flask(__name__)
q = Queue(connection=conn)
job1 = q.enqueue_call(func=method1(), args=(), timeout='1h')
job2 = q.enqueue_call(func=method2(), args=(), timeout='1h')
job3 = q.enqueue_call(func=method3(), args=(), timeout='1h')
job4 = q.enqueue_call(func=method4(), args=(), timeout='1h')
the below code attempts (but fails) to stall the return of the #html template before the processes are finished
while(len(q)>0):
time.sleep(1)
return render_template('result.html')

感谢您提前的帮助。

我认为您必须在时间前面有一些空间。Sleep(1)命令?

变量Q的值不会在while循环内的任何时间变化。因此,它将永久入睡或直接退出。

您需要在段循环中重新评估Q,可能如下:

    while True:
        time.sleep(1)
        q = Queue(connection=conn)
        if len(q) == 0:      
            break

最新更新