public async Task ProcessMessages(string logSource, IApplicationSettingsRepository applicationSettingsRepository, IServiceLogRepository serviceLogRepository, IList <IWorkflowMessage> messages, string exceptionMessagePrepender, IDbTransaction transaction = null) { var tenantInfo = await applicationSettingsRepository.GetTenantInfo(transaction); if (string.IsNullOrWhiteSpace(tenantInfo?.TenantId)) { throw new TenantInfoNotFoundException("No tenant information found. Please contact your administrator."); } if (messages == null || messages.Count <= 0) { return; } foreach (var actionMessage in messages.Where(a => a != null)) { try { await WorkflowMessagingProcessor.Instance.SendMessageAsync(tenantInfo.TenantId, actionMessage); string message = $"Sent {actionMessage.ActionType} message: {actionMessage.ToJSON()} with tenant id: {tenantInfo.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; } } }
public async Task Execute(IApplicationSettingsRepository applicationSettingsRepository, IServiceLogRepository serviceLogRepository, ActionMessage message, IDbTransaction transaction) { var tenantInfo = await applicationSettingsRepository.GetTenantInfo(transaction); var tenantId = tenantInfo?.TenantId; try { if (string.IsNullOrWhiteSpace(tenantId)) { throw new TenantInfoNotFoundException("No tenant information found. Please contact your administrator."); } await WorkflowMessagingProcessor.Instance.SendMessageAsync(tenantId, message); await serviceLogRepository.LogInformation("SendMessageExecutor", $"Sent {message.ActionType} message for tenant {tenantId}: {message.ToJSON()}"); } catch (Exception ex) { await serviceLogRepository.LogError("SendMessageExecutor", $"Failed to send {message.ActionType} message for tenant {tenantId}: {message.ToJSON()}. Exception: {ex.Message}"); throw; } }