public async Task PublishesFunctionExecutionStatus() { _handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()).ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK }); var activity = new ContainerFunctionExecutionActivity(DateTime.UtcNow, "func1", ExecutionStage.InProgress, "QueueTrigger", false); var activities = new List <ContainerFunctionExecutionActivity> { activity }; await _meshServiceClient.PublishContainerActivity(activities); _handlerMock.Protected().Verify <Task <HttpResponseMessage> >("SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(r => IsPublishExecutionStatusRequest(r, activity)), ItExpr.IsAny <CancellationToken>()); }
private async Task FlushFunctionExecutionActivities() { try { if (Interlocked.CompareExchange(ref _flushInProgress, 1, 0) == 0) { try { var currentActivities = new List <ContainerFunctionExecutionActivity>(); if (TryGetCurrentActivities(currentActivities)) { if (_lastHeartBeatTime.AddMinutes(5) < DateTime.UtcNow) { _logger.LogDebug($"Current activities count = {currentActivities.Count}"); _lastHeartBeatTime = DateTime.UtcNow; } if (currentActivities.Any()) { _logger.LogDebug($"Flushing {currentActivities.Count} function activities"); await _meshServiceClient.PublishContainerActivity(currentActivities); } } else { _logger.LogWarning($"Failed to fetch {nameof(ContainerFunctionExecutionActivity)}"); } } finally { _flushInProgress = 0; } } } catch (Exception exc) when(!exc.IsFatal()) { _logger.LogError(exc, nameof(FlushFunctionExecutionActivities)); } }