public bool MessageTimingIsValid(SqsMessage message) { // Ensure that we have a gap between messages to prevent a possible billing issue if (message.timeCreated > DateTime.Now.AddSeconds(-MinimumQueueDelaySeconds)) { return(false); } return(true); }
public async Task ReindexAlias(ReindexRequest request, ILambdaContext context) { try { var alias = request.alias; var indexName = request.fromIndex ?? (await _elasticSearchClient.GetIndicesPointingToAliasAsync(alias))?.First(); this.Log($"Current Index name for alias {alias}: {indexName}"); var indexConfig = request.config ?? await File.ReadAllTextAsync(_indexFilePath); var newIndexName = alias + "_" + DateTime.Now.ToString("yyyyMMddhhmm"); _elasticSearchClient.LowLevel.Indices.Create <BytesResponse>(newIndexName, indexConfig); this.Log($"Created new index with name {newIndexName}"); var response = _elasticSearchClient.ReindexOnServer(r => r .Source(s => s.Index(Indices.Index(indexName))) .Destination(d => d.Index(newIndexName)) .WaitForCompletion(false)); this.Log($"{response.DebugInformation}"); this.Log($"Re-indexed task ID {response.Task.FullyQualifiedId}"); var sqsMessage = new SqsMessage { alias = alias, newIndex = newIndexName, taskId = response.Task.FullyQualifiedId, deleteAfterReindex = request.deleteAfterReindex, timeCreated = DateTime.Now, attempts = 1 }; var sqsResponse = await SendSqsMessageToQueue(JsonConvert.SerializeObject(sqsMessage)); this.Log($"Sent task ID to sqs queue messageId: {sqsResponse?.MessageId}"); } catch (Exception ex) { // We must handle exceptions to prevent AWS retrying on error this.Log($"Exception caught in ReindexAlias {ex.Message}, {ex.StackTrace}, {ex.Source}"); } }