コード例 #1
0
        public async Task Send(Report report, CancellationToken cancellation)
        {
            using var timeoutSource = new CancellationTokenSource(TimeSpan.FromSeconds(15));
            using var linkedSource  = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, cancellation);

            var message =
                report.Operation == ContainerOperation.Restart
                ? CreateRestartMessage(report.Message, report.Container)
                : CreateKillMesage(report.Message, report.Container);

            var payload = JsonSerializer.Serialize(message);

            try
            {
                await
                _retryProvider.RetryOn <HttpRequestException, HttpResponseMessage>(
                    CheckError,
                    TransientHttpStatusCodePredicate,
                    () => Send(_client, _options, payload, _logger, linkedSource.Token));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Report sending failed");
            }
        }
コード例 #2
0
        public async Task Send(MemoryStream jsonStream, CancellationToken cancellation)
        {
            using var timeoutSource = new CancellationTokenSource(TimeSpan.FromSeconds(15));
            using var linkedSource  = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, cancellation);

            try
            {
                await
                _retryProvider.RetryOn <HttpRequestException, HttpResponseMessage>(
                    CheckError,
                    TransientHttpStatusCodePredicate,
                    () => SendRequest(_client, _options, jsonStream, _logger, linkedSource.Token));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Report sending failed", Array.Empty <object>());
            }
        }
コード例 #3
0
        public override async Task <HealthCheckResponse> Handle(HealthCheckRequest request, CancellationToken cancellationToken)
        {
            try
            {
                await
                _retryProvider.RetryOn(
                    (SqlException ex) => TransientErrorNumbers.Contains(ex.Number),
                    _ => false,
                    () => Execute(_factory, HealthQuery, cancellationToken));

                return(Healthy(Engine.SqlServer.Name));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "HealthCheck failed.", Array.Empty <object>());

                return(Unhealthy(Engine.SqlServer.Name, ex.ToString()));
            }
        }
コード例 #4
0
        public override async Task <HealthCheckResponse> Handle(HealthCheckRequest request, CancellationToken cancellationToken)
        {
            try
            {
                IMongoCollection <LogEntry> logEntries = await _collectionFactory.Get <LogEntry>(cancellationToken);

                var response =
                    await
                    _retryProvider.RetryOn <MongoConnectionException, long>(
                        x => true,
                        x => false,
                        () => logEntries.CountDocumentsAsync(new FilterDefinitionBuilder <LogEntry>().Empty));

                return(Healthy(Engine.MongoDb.Name));
            }
            catch (Exception ex)
            {
                return(Unhealthy(Engine.MongoDb.Name, ex.ToString()));
            }
        }
コード例 #5
0
        public override async Task <HealthCheckResponse> Handle(HealthCheckRequest request, CancellationToken cancellationToken)
        {
            using var timeoutSource = new CancellationTokenSource(_options.TimeoutInMs);
            using var linkedSource  = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, cancellationToken);

            try
            {
                _ = await
                    _retryProvider.RetryOn <HttpRequestException, HttpResponseMessage>(
                    x =>
                {
                    if (!x.Data.Contains(nameof(HttpStatusCode)))
                    {
                        return(false);
                    }

                    var statusCode = (HttpStatusCode)x.Data[nameof(HttpStatusCode)];

                    if (statusCode < HttpStatusCode.InternalServerError)
                    {
                        return(statusCode == HttpStatusCode.RequestTimeout);
                    }

                    return(false);
                },
                    x => TransientHttpStatusCodePredicate(x),
                    () => Send(linkedSource.Token));

                return(Healthy(Engine.Slack.Name));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "HealthCheck failed.", Array.Empty <object>());

                return(Unhealthy(Engine.Slack.Name, ex.ToString()));
            }
        }