Make test project useable in a production load testing setting

This commit is contained in:
Andrew Godwin 2016-03-20 17:06:51 -07:00
parent bea5b138ef
commit b3c101bd79
4 changed files with 47 additions and 4 deletions

19
testproject/Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM ubuntu:16.04
MAINTAINER Andrew Godwin <andrew@aeracode.org>
RUN apt-get update && \
apt-get install -y \
git \
python-dev \
python-setuptools \
python-pip && \
pip install -U pip
RUN pip install channels==0.9.5 asgi_redis==0.8.3
RUN git clone https://github.com/andrewgodwin/channels.git /srv/application/
WORKDIR /srv/application/testproject/
EXPOSE 80

View File

@ -0,0 +1,18 @@
version: '2'
services:
redis:
image: redis
daphne:
image: channels-test
build: .
command: daphne -b 0.0.0.0 -p 80 testproject.asgi:channel_layer
ports:
- "80:80"
depends_on:
- redis
worker:
image: channels-test
build: .
command: python manage.py runworker
depends_on:
- redis

View File

@ -0,0 +1,6 @@
import os
from channels.asgi import get_channel_layer
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
channel_layer = get_channel_layer()

View File

@ -29,10 +29,10 @@ DATABASES = {
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgiref.inmemory.ChannelLayer",
"BACKEND": "asgi_redis.RedisChannelLayer",
"ROUTING": "testproject.urls.channel_routing",
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://redis:6379')],
}
},
}
if os.environ.get("USEREDIS", None):
CHANNEL_BACKENDS['default']['BACKEND'] = "asgi_redis.RedisChannelLayer"