the proper way to run django rq in docker microservices setup

徘徊边缘 提交于 2019-12-11 06:34:23

问题


I have somehow bad setup of my docker containers I guess. Because each time I run task from django I see in docker container output of ps aux that there is new process created of python mange.py rqworker mail instead of using the existing one. See the screencast: https://imgur.com/a/HxUjzJ5

the process executed from command in my docker compose for rq worker container looks like this.

#!/bin/sh -e

wait-for-it

for KEY in $(redis-cli -h $REDIS_HOST -n 2 KEYS "rq:worker*"); do
    redis-cli -h $REDIS_HOST -n 2  DEL $KEY
done

if [ "$ENVIRONMENT" = "development" ]; then
    python manage.py rqworkers --worker-class rq.SimpleWorker --autoreload;
else
    python manage.py rqworkers --worker-class rq.SimpleWorker --workers 4;
fi

I am new to docker and wondering a bit that this is started like this without deamonization... but is it a dockerish way of doing thing, right?


回答1:


Here's what I do, with docker-compose:

version: '3'

services:
  web:
    build: .
    image: mysite
    [...]
  rqworker:
    image: mysite
    command: python manage.py rqworker
    [...]
  rqworker_high:
    image: mysite
    command: python manage.py rqworker high
    [...]

Then start with:

$ docker-compose up --scale rqworker_high=4


来源:https://stackoverflow.com/questions/53557531/the-proper-way-to-run-django-rq-in-docker-microservices-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!