Why does my Celery task not start on Heroku?

I currently have an 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 called. However nothing happens and I don't get any error logs from Heroku. Here is my code:

settings.py:

CELERY_BROKER_URL = env('REDIS_URL', default=env('CELERY_BROKER_URL'))#REDIS_URL #redis://localhost:6379
CELERY_RESULT_BACKEND = env('REDIS_URL', default=env('CELERY_BROKER_URL')) #'redis://redis:6379'
CELERY_CACHE_BACKEND = "default"
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'

views.py: task = transcribe_file_task.delay(file_path, audio_language, output_file_type, 'ai_transcribe_output', session_id)

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()

docker-compose.yml:

services:
  web:
    environment:
      ...
       - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
      ...
services:
  celery:
    environment:
      ...
       - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0

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

requirements.txt: environs[django]==9.5.0

I don't use a Procfile.

To set up redis on Heroku I went read the steps in this tutorial and simply followed the url in the 'Heroku Data for Redis' line and installed it. Then I committed to Github and ran >heroku git:remote -a <app name> and pushed to Heroku using >git push heroku main.

Вернуться на верх