3

I created a django app using Channels 2 on heroku but it crash on starting with 503 error code.

2020-04-07T10:05:35.226253+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.mysite.com request_id=317bfbe6-9055-4957-9fbb-8190616c3964 fwd="" dyno= connect= service= status=503 bytes= protocol=https

Procfile :

release: python manage.py migrate
web : daphne myproject.asgi:application --port $PORT --bind 0.0.0.0 -v2 
worker: python manage.py runworker channels -v2

settings.py

ASGI_APPLICATION = 'myproject.routing.application'
# Channels
    CHANNEL_LAYERS = {
    "default": {
         'BACKEND': 'channels_redis.core.RedisChannelLayer',
        "CONFIG": {
            "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
        },

    },
}

asgi.py

import os
import django
from channels.routing import get_default_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
django.setup()
application = get_default_application()
dubus_b
  • 31
  • 2

2 Answers2

1

Have you created an instance of the process web in heroku? You can do it in command line : heroku ps:scale worker=1

Give worker in Procfile as:

worker: python manage.py runworker channels --settings=<project-name>.settings -v2
Jerome
  • 53
  • 1
  • 5
1

Your Procfile should have this instead :

release: python3 manage.py makemigrations && python3 manage.py migrate
web: daphne domecode.asgi:application --port $PORT --bind 0.0.0.0 -v2
worker: python3 manage.py runworker channel_layer -v2

channel_layer instead of channels. Why? Well, look at your settings again, you've declared CHANNEL_LAYER there which you run locally on a Redis instance on Docker. However when deploying you can't run it on Docker ( I mean you technically can use Docker Swarms on Digital Ocean or AWS, I'm not sure how it works on Heroku ) so you need to change it to channel_layer.

Roast Biter
  • 651
  • 1
  • 6
  • 22
  • 1
    You shouldn't put the `makemigrations` command on your server. Migrations are part of your code and should be generated locally and put in your repository. – GwynBleidD Feb 13 '21 at 12:54