Change how indexden exceptions are handled #281
authorCharles Connell <charles@connells.org>
Mon, 27 Jan 2014 19:18:53 +0000 (14:18 -0500)
committerCharles Connell <charles@connells.org>
Mon, 27 Jan 2014 19:18:53 +0000 (14:18 -0500)
karmaworld/apps/notes/models.py
karmaworld/apps/notes/search.py

index eec394fc2985c08ca5c7850131439f1f1b35cbb4..23007cf0ed484c8c5d6707f3d41b770c323b5e5f 100644 (file)
@@ -362,10 +362,12 @@ def note_save_receiver(sender, **kwargs):
         return
     note = kwargs['instance']
 
+    if kwargs['created']:
+        update_note_counts(note)
+
     try:
         index = SearchIndex()
         if kwargs['created']:
-            update_note_counts(note)
             index.add_note(note)
         else:
             index.update_note(note, note.old_instance)
@@ -384,8 +386,11 @@ def note_delete_receiver(sender, **kwargs):
     update_note_counts(kwargs['instance'])
 
     # Remove document from search index
-    index = SearchIndex()
-    index.remove_note(note)
+    try:
+        index = SearchIndex()
+        index.remove_note(note)
+    except Exception:
+        logger.error("Error with IndexDen:\n" + traceback.format_exc())
 
     if note.user:
         GenericKarmaEvent.create_event(note.user, note.name, GenericKarmaEvent.NOTE_DELETED)
index 3ae352d40e9bf8950b684bf55c721b3fed999bef..629b73c9359dd6f46b2fe2b010ad41ef403783e2 100644 (file)
@@ -64,6 +64,7 @@ class SearchIndex(object):
 
         self.api_client = itc.ApiClient(secret.PRIVATE_URL)
         if not self.api_client.get_index(self.index_name).exists():
+            time.sleep(5)
             self.api_client.create_index(self.index_name, {'public_search': False})
 
         self.index = self.api_client.get_index(self.index_name)