Answer the question
In order to leave comments, you need to log in
Celery does not see the module. How to connect celery to FastApi?
There is a project on FastAPI I'm trying to
fasten celery. The problem is that image does not start on docker.
Error:
Unable to load celery application.
The module celery_worker was not found.
"""celery module"""
import os
import time
#celery
from celery import Celery
celery = Celery(__name__)
celery.conf.broker_url = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379")
celery.conf.result_backend = os.environ.get("CELERY_RESULT_BACKEND", "redis://localhost:6379")
@celery.task(name="create_task")
def create_task1(arg1, arg2):
time.sleep(int(arg1+arg2) * 2)
return True
version: "3.9"
services:
db:
image: registry.all-code.com:5000/custom-postgres
build: ./custom-postgres
restart: unless-stopped
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./custom-postgres/custom_postgresql.conf:/etc/postgresql.conf
command: postgres -c config_file=/etc/postgresql.conf
environment:
- POSTGRES_DB=b2market_marketplace_development
- POSTGRES_USER=b2market
- POSTGRES_PASSWORD=postgres
api_py:
build: .
restart: unless-stopped
ports:
- "5000:5000"
depends_on:
- db
command: bash -c "cd b2market_marketplace && alembic upgrade head && uvicorn api.main:app --host 0.0.0.0 --port=5000 --reload"
volumes:
- /b2market_marketplace
- ./alembic:/b2market_marketplace/alembic
- ./api:/b2market_marketplace/api
env_file:
- .env
worker:
container_name: worker
build: .
restart: always
command: celery -A celery_worker.celery worker --loglevel=INFO
volumes:
- /b2market_marketplace
- ./api:/b2market_marketplace/api
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0
depends_on:
- api_py
- redis
redis:
container_name: redis
image: redis:6.2-alpine
Answer the question
In order to leave comments, you need to log in
As a result, a working solution:
It's not entirely clear to me how celery finds this particular task.py
But everything works.
!!!Attention
celery==4.4.7
flower==0.9.7
For the 5th version of celery, the launch code is different. See documentation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question