from celery_haystack.indexes import CelerySearchIndex from celery_haystack.signals import CelerySignalProcessor from celery_haystack.utils import enqueue_task from haystack.exceptions import NotHandled class CelerySignalProcessor(CelerySignalProcessor): def enqueue(self, action, instance, sender, **kwargs): using_backends = self.connection_router.for_write(instance=instance) for using in using_backends: try: connection = self.connections[using] index = connection.get_unified_index().get_index(sender) except NotHandled: continue # Check next backend if isinstance(index, CelerySearchIndex): if action == 'update' and not index.should_update(instance): continue elif action == 'update' \ and instance not in index.index_queryset(): action = 'delete' enqueue_task(action, instance)