Skip to content
Snippets Groups Projects
Verified Commit b286c57e authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Make task API compatible with Celery 4 and 5

parent 1361998e
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ Requirements
* Django 1.8+
* Haystack_ `2.X`_
* Celery_ 3.X
* Celery_ 5.X
You also need to install your choice of one of the supported search engines
for Haystack and one of the supported backends for Celery.
......
......@@ -7,13 +7,14 @@ from .conf import settings
from haystack import connections, connection_router
from haystack.exceptions import NotHandled as IndexNotFoundException
from celery import Task # noqa
from celery import current_app # noqa
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
class CeleryHaystackSignalHandler(Task):
class CeleryHaystackSignalHandler(current_app.Task):
name = "haystack_signal_handler"
using = settings.CELERY_HAYSTACK_DEFAULT_ALIAS
max_retries = settings.CELERY_HAYSTACK_MAX_RETRIES
default_retry_delay = settings.CELERY_HAYSTACK_RETRY_DELAY
......@@ -134,11 +135,13 @@ class CeleryHaystackSignalHandler(Task):
raise ValueError("Unrecognized action %s" % action)
class CeleryHaystackUpdateIndex(Task):
class CeleryHaystackUpdateIndex(current_app.Task):
"""
A celery task class to be used to call the update_index management
command from Celery.
"""
name = "haystack_update_index"
def run(self, apps=None, **kwargs):
defaults = {
'batchsize': settings.CELERY_HAYSTACK_COMMAND_BATCH_SIZE,
......@@ -155,3 +158,7 @@ class CeleryHaystackUpdateIndex(Task):
logger.info("Starting update index")
call_command('update_index', *apps, **defaults)
logger.info("Finishing update index")
current_app.tasks.register(CeleryHaystackSignalHandler)
current_app.tasks.register(CeleryHaystackUpdateIndex)
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