[Python] Make celery auto-reload on docker

Discussão em 'Python' iniciado por Stack, Abril 19, 2025.

  1. Stack

    Stack Membro Participativo

    Trying to add an auto reload to celery on a docker , as i need to develop and test task, changes in configuration i'd like to have auto reload option without need to reload the docker each time.

    following search i got to watchmedo but it doesn't work , still need to reload the docker on every change.

    see compose file:

    worker:
    build:
    dockerfile: DockerfileCelery
    context: .
    command: watchmedo auto-restart --directory=./ --pattern=*.py --recursive -- celery worker --app=worker.celery --loglevel=info --logfile=logs/celery.log
    volumes:
    - ./multi/celery_app:/usr/src/app
    environment:
    - CELERY_BROKER_URL=redis://redisjson:6379
    - CELERY_RESULT_BACKEND=redis://redisjson:6379
    depends_on:
    - redisjson
    - ws


    would appreciate any help

    ########################################## ##########################################

    Update :

    still not working.

    I run a virtual env (Ubuntu).

    cellery.py

    from decouple import AutoConfig

    cwd = os.getcwd()
    DOTENV_FILE = cwd + '/proj/config/.env'


    config = AutoConfig(search_path='DOTENV_FILE')

    app = Celery('proj',
    broker=config('CELERY_BROKER_URL'),
    backend=config('CELERY_RESULT_BACKEND'),
    include=['proj.tasks'])


    app.conf.update(
    result_expires=3600,
    )


    if __name__ == '__main__':
    app.start()


    tasks.py

    from .celery import app


    @app.task
    def add(x, y):
    return x + y




    spinning celery as :

    watchmedo auto-restart --directory=proj/ -p '*.py' --recursive -- celery -A proj worker --concurrency=1 --loglevel=INFO


    It's running and task being processed by worker. But , if make change in tasks.py - no reload. I need to restart celery.

    Continue reading...

Compartilhe esta Página