Python 如何在使用gunicorn的Google App Engine上运行长任务?
GAE flex默认使用gunicorn作为入口点,这很好,但我有一个需要很长时间处理的函数(在数据库中抓取网站和故事数据),默认情况下gunicorn在30秒时超时,然后一个新的工作人员重新开始任务,依此类推 我可以将gunicorn超时设置为20分钟左右,但它看起来并不优雅。有没有办法在gunicorn的“外部”运行这些后端函数,或者在我没有想到的gunicorn配置之外运行这些后端函数?没有客户端,因此完成时间长不是问题 我的app.yaml文件当前如下所示:Python 如何在使用gunicorn的Google App Engine上运行长任务?,python,google-app-engine,gunicorn,Python,Google App Engine,Gunicorn,GAE flex默认使用gunicorn作为入口点,这很好,但我有一个需要很长时间处理的函数(在数据库中抓取网站和故事数据),默认情况下gunicorn在30秒时超时,然后一个新的工作人员重新开始任务,依此类推 我可以将gunicorn超时设置为20分钟左右,但它看起来并不优雅。有没有办法在gunicorn的“外部”运行这些后端函数,或者在我没有想到的gunicorn配置之外运行这些后端函数?没有客户端,因此完成时间长不是问题 我的app.yaml文件当前如下所示: runtime: pytho
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 2
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 3
disk_size_gb: 10
您可以使用异步工作者类,这样就不需要将超时设置为20分钟。默认的工作类是sync。关于工人的文件 使用eventlet异步工作程序(如果使用google客户端库,则不建议使用gevent) 然后在gunicorn实例化中,将worker类设置为'eventlet',并将worker数设置为[number of cores]x2+1(这只是中的建议)。 例如:
CMD exec gunicorn --worker-class eventlet --workers 3 -b :$PORT main:app
或者,使用pubsub和worker描述的实现。这是可行的,但请注意,在Flex环境中,worker(请求和cron)被限制为10分钟。这是一个硬限制。(见附件)
CMD exec gunicorn --worker-class eventlet --workers 3 -b :$PORT main:app