Update initialization of celery.

* Update module path in supervisor configuration
* Move celery configuration entirely to olympia.amo.celery
* Fix paths in reindex management command
This commit is contained in:
Christopher Grebs 2016-02-01 20:03:51 +01:00
Родитель 0130503f3e
Коммит 18f4ef681a
4 изменённых файлов: 23 добавлений и 36 удалений

Просмотреть файл

@ -8,7 +8,7 @@ logfile=/code/logs/supervisord-celery.log
# Changes:
# - Set concurrency (number of workers) back to the default
# - The code auto-reloads for development
command=celery -A olympia worker --autoreload -E --loglevel=INFO
command=celery -A olympia.amo.celery:app worker --autoreload -E --loglevel=INFO
directory=/code
stopasgroup=true
autostart=true
@ -16,6 +16,8 @@ redirect_stderr=true
stdout_logfile=logs/docker-celery.log
stdout_logfile_maxbytes=1MB
stopsignal=KILL
environment=DJANGO_SETTINGS_MODULE='settings'
# The following sections enable supervisorctl.

Просмотреть файл

@ -14,6 +14,8 @@ from celery.signals import task_failure, task_postrun, task_prerun
from celery.task.sets import TaskSet
from django_statsd.clients import statsd
from post_request_task.task import PostRequestTask
from raven import Client
from raven.contrib.celery import register_signal, register_logger_signal
from olympia.amo.utils import chunked, utc_millesecs_from_epoch
@ -27,7 +29,18 @@ task = app.task
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(settings.INSTALLED_APPS)
# See olympia.startup::init_celery() for more configuration.
# Hook up Sentry in celery.
raven_client = Client(settings.SENTRY_DSN)
# register a custom filter to filter out duplicate logs
register_logger_signal(raven_client)
# hook into the Celery error handler
register_signal(raven_client)
# After upgrading raven we can specify loglevel=logging.INFO to override
# the default (which is ERROR).
register_logger_signal(raven_client)
@task_failure.connect

Просмотреть файл

@ -20,7 +20,8 @@ from olympia.lib.es.utils import (
timestamp_index)
logger = logging.getLogger('z.elasticsearch')
time_limits = settings.CELERY_TIME_LIMITS['lib.es.management.commands.reindex']
time_limits = settings.CELERY_TIME_LIMITS[
'olympia.lib.es.management.commands.reindex']
ES = get_es()
@ -231,9 +232,10 @@ class Command(BaseCommand):
# the soft and hard time limits on the @task decorator. But we're not
# using the @task decorator here, but a decorator from celery_tasktree.
if not getattr(settings, 'CELERY_ALWAYS_EAGER', False):
control.time_limit('lib.es.management.commands.reindex.index_data',
soft=time_limits['soft'],
hard=time_limits['hard'])
control.time_limit(
'olympia.lib.es.management.commands.reindex.index_data',
soft=time_limits['soft'],
hard=time_limits['hard'])
try:
tree.apply_async()

Просмотреть файл

@ -71,35 +71,6 @@ def init_amo():
amo = __import__('olympia.amo')
def init_celery():
"""
Initialize Celery, and make our app instance available as `celery_app`
for use by the `celery` command.
"""
from django.conf import settings
from raven import Client
from raven.contrib.celery import register_signal, register_logger_signal
from olympia.amo import celery
# I think `manage.py celery` relies on this global? We typically don't run
# celery like that anymore though.
global celery_app
celery_app = celery.app
# Hook up Sentry in celery.
client = Client(settings.SENTRY_DSN)
# register a custom filter to filter out duplicate logs
register_logger_signal(client)
# hook into the Celery error handler
register_signal(client)
# After upgrading raven we can specify loglevel=logging.INFO to override
# the default (which is ERROR).
register_logger_signal(client)
def configure_logging():
"""Configure the `logging` module to route logging based on settings
in our various settings modules and defaults in `lib.log_settings_base`."""
@ -126,5 +97,4 @@ init_jinja2()
init_amo()
configure_logging()
init_jingo()
init_celery()
load_product_details()