Skip to content

Commit

Permalink
ended up boosting celery config from neurovault
Browse files Browse the repository at this point in the history
  • Loading branch information
rwblair committed Jan 15, 2016
1 parent ccc3345 commit d523173
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 19 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM python:3.4
FROM python:3.5

ENV PYTHONUNBUFFERED 1

#RUN groupadd -r open_fmri && useradd --create-home --home-dir /home/open_fmri -r -g open_fmri open_fmri
#USER open_fmri
#WORKDIR /home/open_fmri

RUN apt-get update && apt-get install -y postgresql-client

# Requirements have to be pulled and installed here, otherwise caching won't work
ADD ./requirements.txt /requirements.txt

RUN pip install -r /requirements.txt
#RUN groupadd -r open_fmri && useradd -r -g open_fmri open_fmri
10 changes: 9 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,23 @@ nginx:
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"

redis:
restart: always
image: redis

worker:
build: .
command: celery worker -A open_fmri.celery -Q default -n default@%h --loglevel=debug
env_file: .env
volumes:
- .:/app
links:
volumes_from:
- uwsgi
links:
- redis
working_dir: /app


opensmtpd:
build: ./opensmtpd/
volumes:
Expand Down
14 changes: 14 additions & 0 deletions open_fmri/apps/dataset/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import datetime

from celery import shared_task, Celery

app = Celery('open_fmri')
app.config_from_object('django.conf:settings.base')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

@app.task(name='test_parse')
def test_parse():
logger = test_parse.get_logger()
logger.info(str(datetime.now))
return datetime.now()

20 changes: 5 additions & 15 deletions open_fmri/celery.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
from __future__ import absolute_import

import os

from celery import Celery
from django.conf import settings

from django.conf import settings # noqa

app = Celery('open_fmri')
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'neurovault.settings')
celery = Celery('open_fmri')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

app.conf.update(
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
)

@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
celery.config_from_object('django.conf:settings')
celery.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
21 changes: 21 additions & 0 deletions open_fmri/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import os
from os.path import join, abspath, dirname

from celery.schedules import crontab
from kombu import Exchange, Queue

# PATH vars
here = lambda *x: join(abspath(dirname(__file__)), *x)
PROJECT_ROOT = here("..")
Expand Down Expand Up @@ -166,6 +169,24 @@
'SECRET_TOKEN': os.environ.get('OPBEAT_SECRET_TOKEN', ''),
}

# Celery config
BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_DEFAULT_QUEUE = 'default'
CELERY_QUEUES = (
Queue('default', Exchange('default'), routing_key='default'),
)

CELERYBEAT_SCHEDULE = {
'Parse Logs': {
'task': 'parse_test',
'schedule': crontab()
},
}

# .local.py overrides all the common settings.
try:
from .local import *
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ model_mommy
opbeat
pillow
psycopg2
redis
requests
requests-cache
uwsgi

0 comments on commit d523173

Please sign in to comment.