public async Task Process_RetriableResults_FailAndRetry() { var channel = _outputChannelDa.FindAsync(TestOutputChannelKey).GetAwaiter().GetResult(); var jobId = channel.JobId; var stepId = Guid.NewGuid().ToString(); var queue = _nebulaService.NebulaContext .JobStepSourceBuilder .BuildDelayedJobQueue <HttpPushOutgoingQueueStep>(jobId); var step = new HttpPushOutgoingQueueStep { Category = channel.FilterCriteria.Category, Tag = channel.FilterCriteria.Tag, Payload = "test", StepId = stepId }; queue.Enqueue(step, DateTime.UtcNow).GetAwaiter().GetResult(); var outgoingMessageLogs = await GetLogsWithDelay(stepId); Assert.Equal(outgoingMessageLogs.Count, _retryConfiguration.Value.Count + 1); if (outgoingMessageLogs.Count > 1) { var diff = outgoingMessageLogs[1].ResponseTime.Subtract(outgoingMessageLogs[0].ResponseTime).TotalMinutes; Assert.True(Math.Abs(diff - _retryConfiguration.Value.Interval) < 0.05); } }
public ProcessorRetryTests() { Options = Microsoft.Extensions.Options.Options.Create(retryConfiguration); Processor = new HttpPushOutgoingQueueProcessor(MockLogger.Object, MockMessageDa.Object, Options); NebulaContext.RegisterJobProcessor(Processor, typeof(HttpPushOutgoingQueueStep)); _step = new HttpPushOutgoingQueueStep { Category = "test_category", FailCount = 0, Payload = "test_message" }; }
private void MessageReceived(object sender, Message <Null, string> message) { var publishInput = JsonConvert.DeserializeObject <PublishInput>(message.Value); if (!publishInput.ValidateTags()) { _logger.LogWarning("Received message with invalid tags", publishInput); return; } if (string.IsNullOrWhiteSpace(publishInput.Category)) { _logger.LogWarning("Received message with invalid category", publishInput); return; } var jobIdTagPairs = _nebulaService.GetJobIdTagPairs(publishInput.Tenant, publishInput.Category, publishInput.Tags); if (!jobIdTagPairs.Any()) { _logger.LogWarning($"active job not found for " + $"Tenant: {publishInput.Tenant} " + $"Category: {publishInput.Category} " + $"Tags: {{{string.Join(", ", publishInput.Tags)}}}"); return; } var step = new HttpPushOutgoingQueueStep { Payload = publishInput.Payload.ToString(), Category = publishInput.Category, StepId = Guid.NewGuid().ToString() }; foreach (var(key, value) in jobIdTagPairs) { step.Tag = value; var queue = _nebulaService.NebulaContext .JobStepSourceBuilder .BuildDelayedJobQueue <HttpPushOutgoingQueueStep>(key); _logger.LogInformation($"queueing message: {message.Value}"); queue.Enqueue(step, DateTime.UtcNow).GetAwaiter().GetResult(); } }
public void Process_AllDataSet_Success() { StubHttp.Stub(x => x.Post("/endpoint")) .WithStatus(HttpStatusCode.OK); var step = new HttpPushOutgoingQueueStep { Category = "test_category", FailCount = 0, Payload = "test_message" }; Processor.Initialize(JobData, NebulaContext); var result = Processor.Process(new List <HttpPushOutgoingQueueStep> { step }).GetAwaiter().GetResult(); Assert.Equal(0, result.ItemsFailed); Assert.Equal(0, result.ItemsRequeued); }
public void Process_WrongTargetUrl_Fail() { StubHttp.Stub(x => x.Post("/endpoint")) .WithStatus(HttpStatusCode.NotFound); JobConfiguration.Parameters = JsonConvert.SerializeObject(Parameters); var step = new HttpPushOutgoingQueueStep { Category = "test_category", FailCount = 0, Payload = "test_message" }; Processor.Initialize(JobData, NebulaContext); var result = Processor.Process(new List <HttpPushOutgoingQueueStep> { step }).GetAwaiter().GetResult(); Assert.Equal(1, result.ItemsFailed); }