1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Why does my Celery task not start on Heroku?

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 15:52.

  1. Stack

    Stack Membro Participativo

    I currently have a dockerized django app deployed on Heroku. I've recently added celery with redis. The app works fine on my device but when I try to deploy on Heroku everything works fine up until the Celery task should be started. However nothing happens and I don't get any error logs from Heroku. I use celery-redis and followed their setup instructions but my task still does not start when I deploy to Heroku. Here is my code:

    heroku.yml:

    setup:
    addons:
    - plan: heroku-postgresql
    - plan: heroku-redis
    build:
    docker:
    web: Dockerfile
    celery: Dockerfile
    release:
    image: web
    command:
    - python manage.py collectstatic --noinput
    run:
    web: gunicorn mysite.wsgi
    celery: celery -A mysite worker --loglevel=info



    views.py:

    from celery.result import AsyncResult
    task = transcribe_file_task.delay(file_path, audio_language, output_file_type, 'ai_transcribe_output', session_id)


    task.py:

    from celery import Celery
    app = Celery('transcribe')#
    @app.task

    def transcribe_file_task(path, audio_language, output_file_type, dest_dir, session_id):
    print(str("TASK: "+session_id))

    #rest of code

    return output_file


    celery.py:

    from __future__ import absolute_import, unicode_literals
    import os
    from celery import Celery
    from django.conf import settings

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

    app = Celery("mysite")

    app.config_from_object("django.conf:settings", namespace="CELERY")

    app.autodiscover_tasks()


    I ensured that my CELERY_BROKER_URL and CELERY_RESULT_BACKEND are getting the correct REDIS_URL from environment variables by having it printing it's value before the task is to be started. So I know that's not the issue

    Continue reading...

Compartilhe esta Página