Force solr updates to process each resource in SOLRQueue
@@ -10,43 +10,46 @@ from hs_core.models import SOLRQueue
logger = logging.getLogger(__name__)
-def solr_update(instance):
+def solr_update(index, instance):
""" Update a resource's SOLR record """
- from hs_core.models import BaseResource
- from hs_core.search_indexes import BaseResourceIndex
logger.info('updating {}'.format(instance.short_id))
- index = BaseResourceIndex()
- newbase = BaseResource.objects.get(pk=instance.pk)
try:
- index.update_object(newbase)
+ index.update_object(instance)
except NotHandled:
logger.exception("Failure: changes to %s with short_id %s not added to Solr Index.",
- str(type(instance)), newbase.short_id)
+ str(type(instance)), instance.short_id)
-def solr_delete(instance):
+def solr_delete(index, instance):
""" Delete a resource from SOLR before deleting from Django """
- from hs_core.models import BaseResource
- from hs_core.search_indexes import BaseResourceIndex
logger.info('deleting {}'.format(instance.short_id))
- index = BaseResourceIndex()
- newbase = BaseResource.objects.get(pk=instance.pk)
try:
- index.remove_object(newbase)
+ index.remove_object(instance)
except NotHandled:
logger.exception("Failure: delete of %s with short_id %s failed.",
- str(type(instance)), newbase.short_id)
+ str(type(instance)), instance.short_id)
def solr_batch_update():
""" update SOLR for resources in the SOLRQueue """
logger.info('starting batch update')
+ from hs_core.models import BaseResource
+ from hs_core.search_indexes import BaseResourceIndex
+ index = BaseResourceIndex()
for instance in SOLRQueue.read_and_clear():
logger.info('checking {}'.format(instance.short_id))
- if instance.show_in_discover: # if object should be displayed now
- solr_update(instance)
+ try:
+ newbase = BaseResource.objects.get(pk=instance.pk)
+ if newbase.show_in_discover: # if object should be displayed now
+ solr_update(index, newbase)
else: # not to be shown in discover
- solr_delete(instance)
+ solr_delete(index, newbase)
+ except BaseResource.DoesNotExist:
+ logger.info("Failure: %s with short_id %s does not exist, skipping",
+ str(type(instance)), instance.short_id)
+ except: # catch broad exception to continue processing resources in the queue
+ logger.exception("Unhandled exception raised when updating solr for %s with shortid %s",
+ str(type(instance)), instance.short_id)
class HydroRealtimeSignalProcessor(RealtimeSignalProcessor):
