[Python] Celery is not running despite correct configuration - using Django, Celery 5+, and...

Discussão em 'Python' iniciado por Stack, Junho 27, 2025.

  1. Stack

    Stack Membro Participativo

    Despite what appears to be a correct initial configuration, Celery tasks are not running. The logging system does not show any errors. This is a new setup of Celery version 5+ running on Python 3.12+. Full server-side configuration has been added. All required packages and dependencies have been installed, and the application itself does not raise any errors.

    What could be the reason the test Celery task is not executing every minute as scheduled, according to the interval specified in settings.py?

    tasks.py

    from celery import shared_task
    from datetime import datetime
    from .models import CeleLog

    @shared_task
    def get_all_weather_data():
    now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    CeleLog.objects.create(content=f"Current time: {now}")
    print(f"Logged time: {now}")


    settings.py

    CELERY_BROKER_URL = 'amqp://localhost'
    from celery.schedules import crontab
    CELERY_BEAT_SCHEDULE = {
    'log-every-minute': {
    'task': 'company_dashboard.tasks.get_all_weather_data', # <- ścieżka do funkcji
    'schedule': crontab(minute='*/1'),
    },
    }


    celery.py - project

    import os
    from celery import Celery
    from django.conf import settings


    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app_rama.settings')

    app = Celery('app_rama')

    app.config_from_object('django.conf:settings')
    app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


    init.py - project

    from .celery import app as celery_app


    app-celery-worker.conf

    [program:app-celery-worker]
    command=/home/app/bin/celery -A app_rama worker -l INFO
    directory=/home/app/app
    user=app
    numprocs=1
    stdout_logfile=/home/app/logs/app-rama-worker.log
    stderr_logfile=/home/app/logs/app-rama-worker.log
    autostart=true
    autorestart=true
    startsecs=10
    stopwaitsecs=600
    killasgroup=true
    priority=998


    app-celery-beat.conf

    [program:app-celery-beat]
    command=/home/app/bin/celery -A app_rama beat -l INFO
    directory=/home/app/app
    user=app
    numprocs=1
    stdout_logfile=/home/app/logs/app-rama-worker.log
    stderr_logfile=/home/app/logs/app-rama-worker.log
    autostart=true
    autorestart=true
    startsecs=10
    stopwaitsecs=600
    killasgroup=true
    priority=998


    And i run: sudo supervisorctl reread sudo supervisorctl update sudo service nginx restart sudo supervisorctl restart app sudo supervisorctl start app-celery-worker sudo supervisorctl start app-celery-beat

    I've been trying to solve this for a few hours now. The logs don’t show any errors, and the configuration seems to have been correct. I suspect the issue might be related to how Celery is being launched. I don’t see any test tasks or models running in the logs every minute, so maybe I’m not launching the new Celery version 5 correctly in settings.py? I’d really appreciate any help.

    Continue reading...

Compartilhe esta Página