Skip to content

Instantly share code, notes, and snippets.

@joshourisman
Created April 23, 2015 14:43
Show Gist options
  • Save joshourisman/89b1acb146548e94f0ed to your computer and use it in GitHub Desktop.
Save joshourisman/89b1acb146548e94f0ed to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment