我正在尝试使用CRON在App Engine上安排一项任务,该cron将在后台连续运行。我已经编写了CRON任务,它在本地服务器上正常工作,但是当我通过Google Cloud Console运行它后,它在30秒后失败。
cron.yaml:
cron:
- description: daily tweets streaming
url: /path/to/cron
schedule: every 24 hours
views.py:
def testing(request):
print("okasha---")
from streamTweets import start_stream
start_stream()
urls.py:
url(r'^path/to/cron$', views.testing, name="testing"),
我已经阅读了一种说明将任务分为子任务的解决方案,但我无法将其分为子任务。我的日志说找不到条目,但是当我直接通过URL访问它时,它会启动脚本,但是30秒后,它给出了502个错误的网关错误。
您的应用程序是否使用Gunicorn?
枪支默认情况下将使用同步工人,并在30秒后将其杀死。在我的Google App Engine应用程序上,它在30秒后杀死了所有内容,无论它是云任务还是CRON作业。
2种可能的方法是:
使用异步工人,请参阅此处:如何在使用Gunicorn的Google App Engine上运行长任务?我没有尝试过。
或更改同步工人的超时,这是我的app.yaml' - timeout = 600'设置了枪支工人的超时。这是针对Google App Engine Python 3标准应用。
runtime: python37
entrypoint: gunicorn -b :$PORT main:app --workers=4 --timeout=600
instance_class: B8
basic_scaling:
max_instances: 11
idle_timeout: 10m
runtime_config:
python_version: 3
handlers:
- url: '/.*'
script: auto