skip to Main Content

I have the following heroku.yml. The ‘containers’ share the same Dockerfile:

build:
  docker:
    web: Dockerfile
    celery: Dockerfile
    celery-beat: Dockerfile
release:
  image: web
  command:
    - python manage.py migrate users && python manage.py migrate
run:
  web: python manage.py runserver 0.0.0.0:$PORT
  celery: celery --app=my_app worker --pool=prefork --concurrency=4 --statedb=celery/worker.state -l info
  celery-beat: celery --app=my_app beat -l info

I intended to have three containers, but it turns out that Heroku accepts only one web and the other should be workers.

So what do I modify at heroku.yml to have celery and celery-beat containers as worker?

UPDATE

I’ve changed the heroku.yml to the following, but Heroku keeps only the last worker (i.e. celery beat) and ignores the first worker:

build:
  docker:
    web: Dockerfile
release:
  image: web
  command:
    - python manage.py migrate users && python manage.py migrate
run:
  web: python manage.py runserver 0.0.0.0:$PORT
  worker:
    command:
      - celery --app=my_app worker --pool=prefork --concurrency=4 --statedb=celery/worker.state -l info
    image: web
  worker:
    command:
      - celery --app=my_app beat -l info
    image: web

What am I missing?

2

Answers


  1. The name worker isn’t really important:

    No process types besides web and release have special properties

    So just give them different names:

    run:
      web: python manage.py runserver 0.0.0.0:$PORT
      celery_worker:
        command:
          - celery --app=my_app worker --pool=prefork --concurrency=4 --statedb=celery/worker.state -l info
        image: web
      celery_beat:
        command:
          - celery --app=my_app beat -l info
        image: web
    

    When you scale those processes, use the names celery_worker and celery_beat.

    Login or Signup to reply.
  2. A better option is to combine the celery worker and beat in a single worker / command : (can only be done on Linux os)

    run:
      web: python manage.py runserver 0.0.0.0:$PORT
      celery_worker:
        command:
          - celery --app=my_app worker --pool=prefork --concurrency=4 --statedb=celery/worker.state -l info --beat -l info
        image: web
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search