Skip to content
Snippets Groups Projects
Commit 46e28c37 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Add celery_once

parent 0be2c144
No related branches found
No related tags found
1 merge request!39Add celery_once
from celery import shared_task
from celery_once import QueueOnce
from django.conf import settings
from arkindex.documents.models import Element, Act, Transcription
from arkindex.documents.indexer import Indexer
@shared_task
@shared_task(base=QueueOnce, once={'graceful': True})
def refresh_db_cache():
'''
Refresh materialized views
......@@ -12,7 +13,7 @@ def refresh_db_cache():
Element.objects.refresh_cache()
@shared_task
@shared_task(base=QueueOnce, once={'graceful': True})
def reindex_acts():
'''
Reindex all acts
......@@ -22,7 +23,7 @@ def reindex_acts():
indexer.run_index(settings.ES_INDEX_ACTS, Act.INDEX_TYPE, acts, bulk_size=100)
@shared_task
@shared_task(base=QueueOnce, once={'graceful': True})
def reindex_transcriptions():
'''
Reindex all transcriptions
......
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'arkindex.project.settings')
......@@ -12,6 +13,7 @@ app = Celery('arkindex')
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.ONCE = settings.CELERY_ONCE
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
......
......@@ -268,6 +268,13 @@ LOGGING = {
# Async Workers
CELERY_BROKER_URL = os.environ.get('QUEUE_URL', 'redis://localhost:6379/0')
CELERY_RESULT_BACKEND = os.environ.get('QUEUE_URL', 'redis://localhost:6379/0')
CELERY_ONCE = {
'backend': 'celery_once.backends.Redis',
'settings': {
'url': os.environ.get('QUEUE_URL', 'redis://localhost:6379/0'),
'default_timeout': 3600,
}
}
# Email
if os.environ.get('EMAIL_HOST'):
......
celery==4.1.1
celery_once==2.0.0
certifi==2017.7.27.1
chardet==3.0.4
Django==2.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment