fastapi_best_architecture icon indicating copy to clipboard operation
fastapi_best_architecture copied to clipboard

Celery with asyncio?

Open downdawn opened this issue 1 year ago • 1 comments

Hi, @wu-clan

Celery scheduled tasks cannot be executed

bdb52e620133cb39d87751f53ed28ea

Solutions related to asyncio https://stackoverflow.com/questions/39815771/how-to-combine-celery-with-asyncio

5b0e766934b4c6826ddfc9611064a87

The method above uses async_to_sync to forcibly convert to a synchronous method, which runs normally on the Windows 10 system, but requires additional configuration.

# windows 下需要设置环境变量,不推荐使用 windows 下开发 celery
# https://github.com/celery/celery/pull/4078
#
import os

os.environ.setdefault('FORKED_BY_MULTIPROCESSING', '1')

In the CentOS 7 system environment, after deployment using Supervisor and Gunicorn, observe it several times and an exception may occur. image

If Celery cannot be compatible with asyncio, then performing database operations within tasks will be affected.

downdawn avatar May 04 '24 13:05 downdawn

https://github.com/celery/celery/issues/7874

wu-clan avatar Jul 26 '24 09:07 wu-clan

Hi, @downdawn Has successfully run the asynchronous task with a temporary solution, see pr TODO for details.

wu-clan avatar Jul 26 '24 11:07 wu-clan

nice

downdawn avatar Jul 27 '24 09:07 downdawn