azure - 无法在 Azure 应用服务上成功运行 Celery 和 Celery Beat

标签 azure django-rest-framework azure-web-app-service celery celerybeat

我已将 Django REST API 部署为 Azure 上的应用服务。在我的 DRF API 中,我使用 Celery 和 Celery Beat 来过夜运行 CRON 作业。

我设置了 Azure Redis 缓存,并将代理 URL 设置为其位置并运行了测试。当我在本地初始化它时,一切正常。

但是,当尝试使用startup.sh 文件部署API 以在服务器重新加载时运行celery 时,它会崩溃。我无法联系到管理员,并且不再返回回复。日志显示这些错误:

Container app-api for site app-api did not start within expected time limit.
Container app-api didn't respond to HTTP pings on port: 8000, failing site start

我想知道是不是我设置错了。在应用服务>配置>常规设置>启动命令中:我把startup.sh

startup.sh 文件位于根项目级别,包含:

gunicorn — bind=0.0.0.0 — timeout 600 api.wsgi & celery -A api.celery worker -l info & celery -A api.celery beat -l info

更不寻常的是,当我删除启动文件时,一切都会再次运行(手动运行 celery/beat 命令后),并且即使应用程序服务没有响应,它似乎也运行了定期任务。

为什么这在本地启动时可以工作,但一旦我使用启动文件并保存设置,导致服务器重新启动,它就会中断。

我尝试了许多不同的启动文件组合,但没有成功。任何帮助将不胜感激。

最佳答案

我遇到了同样的问题,并通过在启动应用程序命令之前调用 celery Worker 和 Beat 来解决。我也在使用gunicorn。

export LANG=C.UTF-8

celery -A <your_application> worker -l INFO --concurrency=3 --pool=eventlet & celery -A <your_application> beat -l INFO -S django_celery_beat.schedulers:DatabaseScheduler & gunicorn --bind=0.0.0.0:8000 <your_application>.wsgi

关于azure - 无法在 Azure 应用服务上成功运行 Celery 和 Celery Beat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72634652/

相关文章:

azure - 维护期间 Azure Functions 会发生什么情况?

node.js - Azure Function Node.js 无法为运行时启动新的语言工作线程 : node

django - 尝试访问 ViewSet 创建定义中的 request.data 时出现 KeyError 'id'

azure - Azure 中的反向代理与 Web 应用

linux - 如何使用 unixODBC 和 FreeTDS 连接到 Azure?

django - 为两个使用相同模型的不同 View 集注册一个路由

django-rest-framework - django-rest-swagger 如何记录 API

asp.net-core - 在 ASP.NET Core 中禁用分块

Azure AD 注销 URL - 重定向不起作用

azure - 已达到表单识别器用户限制?