Integrated Celery startup / management / config with PillarServer.

This commit is contained in:
2017-06-01 16:15:44 +02:00
parent e7d268bde6
commit 5af54237b9
7 changed files with 41 additions and 29 deletions

View File

@@ -4,12 +4,10 @@ import bson
from pillar import current_app
from .celery_cfg import celery_cfg
log = logging.getLogger(__name__)
@celery_cfg.task(ignore_result=True)
@current_app.celery.task(ignore_result=True)
def push_updated_user_to_algolia(user_id: str):
"""Push an update to the Algolia index when a user item is updated"""

View File

@@ -1,20 +0,0 @@
from celery import Celery
task_modules = [
'pillar.celery.tasks',
'pillar.celery.algolia_tasks',
]
celery_cfg = Celery('proj',
backend='redis://redis/1',
broker='amqp://guest:guest@rabbit//',
include=task_modules,
task_track_started=True)
# Optional configuration, see the application user guide.
celery_cfg.conf.update(
result_expires=3600,
)
if __name__ == '__main__':
celery_cfg.start()

View File

@@ -1,12 +1,12 @@
import logging
import typing
from .celery_cfg import celery_cfg
from pillar import current_app
log = logging.getLogger(__name__)
@celery_cfg.task(track_started=True)
@current_app.celery.task(track_started=True)
def long_task(numbers: typing.List[int]):
_log = log.getChild('long_task')
_log.info('Computing sum of %i items', len(numbers))
@@ -18,4 +18,3 @@ def long_task(numbers: typing.List[int]):
_log.info('Computed sum of %i items', len(numbers))
return thesum