Created
December 17, 2017 07:05
-
-
Save mmautner/b0821fa054cf584db6275f6253e740ca to your computer and use it in GitHub Desktop.
celery docker-compose example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import environ | |
from celery import Celery | |
environ.setdefault('CELERY_CONFIG_MODULE', 'celery_config') | |
app = Celery() | |
app.config_from_envvar('CELERY_CONFIG_MODULE') | |
@app.task | |
def add(x, y): | |
return x + y | |
@app.task | |
def tsum(*args, **kwargs): | |
print(args) | |
print(kwargs) | |
return sum(args[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import environ | |
broker_url = environ['BROKER_URL'] | |
result_backend = environ['RESULT_BACKEND'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
rabbitmq: | |
image: rabbitmq:3.6.6 | |
ports: | |
- "5672:5672" | |
environment: | |
- RABBITMQ_DEFAULT_USER=admin | |
- RABBITMQ_DEFAULT_PASS=mypass | |
redis: | |
image: redis | |
ports: | |
- "6379:6379" | |
worker: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
image: madefire/chordtest | |
command: ['celery', 'worker', '-A', 'app.app', '-l', 'info'] | |
environment: | |
- BROKER_URL=amqp://admin:mypass@rabbitmq:5672// | |
- RESULT_BACKEND=redis://redis:6379/0 | |
- C_FORCE_ROOT=true | |
volumes: | |
- ./:/app/ | |
depends_on: | |
- rabbitmq | |
- redis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.4 | |
ADD . /app/ | |
WORKDIR /app/ | |
RUN pip install -r requirements.txt | |
CMD ["echo", "hello"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
celery[redis]==4.0.2 | |
ipython==6.0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment