public QueueIndexer(IAmazonSQS queueClient, HttpClient httpClient, IndexingCore indexingCore, ILogging logger) { QueueClient = queueClient; IndexingCore = indexingCore; HttpClient = httpClient; Logger = logger; }
private async Task IndexAndMarkComplete(Message message) { try { var model = JsonConvert.DeserializeObject <ClassificationModel>(message.Body); using var indexer = new IndexerFactory().GetIndexer(model.Source, HttpClient); if (indexer == null) { Logger.Log($"Failed to process message due to unknown source {model.Source} for message: {message.Body}"); return; } await IndexingCore.Index(indexer, model); } catch (Exception e) when(e is ProtectedClassificationException || e.InnerException is ProtectedClassificationException) { Logger.Log($"Skipping index request due to attempting to re-index protected classification: {e.Message} for message: {message.Body}. Error: " + e); await QueueClient.DeleteMessageAsync(QUEUE_URL, message.ReceiptHandle); return; } catch (Exception e) when(e is StitchedImageException || e.InnerException is StitchedImageException) { Logger.Log($"Failed to stitch image tiles together. The image can be reprocessed by the queue: {e.Message} for message: {message.Body}. Error: " + e); return; } catch (Exception e) when(e is NoIndexContentException || e.InnerException is NoIndexContentException) { Logger.Log($"Failed to find content for image. The image can be reprocessed by the queue: {e.Message} for message: {message.Body}. Error: " + e); return; } catch (Exception e) { Logger.Log($"Failed to process message due to unknown error: {e.Message} for message: {message.Body}. Error: " + e); return; } await QueueClient.DeleteMessageAsync(QUEUE_URL, message.ReceiptHandle); }