public static async Task Send(IEnumerable<int> artifactIds, TenantInformation tenant, ActionMessage sourceMessage, IWorkflowMessagingProcessor workflowMessagingProcessor) { var artifacts = artifactIds?.ToList(); if (artifacts == null || !artifacts.Any()) { Logger.Log("No artifact IDs found; no need to send Artifact Changed Message", sourceMessage, tenant); return; } Logger.Log($"Found {artifacts.Count} artifact IDs", sourceMessage, tenant); var artifactsChangedMessage = new ArtifactsChangedMessage { TransactionId = sourceMessage.TransactionId, RevisionId = sourceMessage.RevisionId, UserId = sourceMessage.UserId, ChangeType = ArtifactChangedType.Indirect }; while (artifacts.Any()) { var batch = artifacts.Take(MaximumArtifactBatchSize).ToList(); artifactsChangedMessage.ArtifactIds = batch; Logger.Log($"Sending Artifacts Changed Message for {batch.Count} artifact IDs: {string.Join(",", batch)}", sourceMessage, tenant); await ActionMessageSender.Send(artifactsChangedMessage, tenant, workflowMessagingProcessor); Logger.Log("Finished sending Artifacts Changed Message", sourceMessage, tenant); artifacts = artifacts.Skip(MaximumArtifactBatchSize).ToList(); } }
public static async Task ProcessMessages(string logSource, TenantInformation tenant, IServiceLogRepository serviceLogRepository, IList <IWorkflowMessage> messages, string exceptionMessagePrepender, IWorkflowMessagingProcessor workflowMessagingProcessor) { if (messages == null || messages.Count <= 0) { return; } var processor = workflowMessagingProcessor ?? WorkflowMessagingProcessor.Instance; foreach (var actionMessage in messages.Where(a => a != null)) { try { await ActionMessageSender.Send((ActionMessage)actionMessage, tenant, processor); string message = $"Sent {actionMessage.ActionType} message: {actionMessage.ToJSON()} with tenant id: {tenant.TenantId} to the Message queue"; await serviceLogRepository.LogInformation(logSource, message); } catch (Exception ex) { string message = $"Error while sending {actionMessage.ActionType} message with content {actionMessage.ToJSON()}. {exceptionMessagePrepender}. Exception: {ex.Message}. StackTrace: {ex.StackTrace ?? string.Empty}"; await serviceLogRepository.LogError(logSource, message); throw; } } }