Created
April 23, 2015 14:43
-
-
Save joshourisman/89b1acb146548e94f0ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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