Пример #1
0
        public async Task <IActionResult> EnqueueAsync(
            [FromServices] IRabbitMQProducer rabbitMQProducer, // Using FromServices to allow lazy creation of RabbitMQ connection
            string source,
            string eventName = null)
        {
            await Task.Delay(100);

            FailGenerator.FailIfNeeded(1);

            var apiFullUrl = $"{timeApiUrl}/api/time/localday";

            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug("Getting time from {url}", apiFullUrl);
            }

            var day = await httpClientFactory.CreateClient().GetStringAsync(apiFullUrl);

            var jsonResponse = new EnqueuedMessage {
                Day = day, EventName = eventName, Source = source ?? "N/a"
            };
            var message = System.Text.Json.JsonSerializer.Serialize(jsonResponse);

            rabbitMQProducer.Publish(message);

            metrics.TrackItemEnqueued(1, source);

            return(new JsonResult(jsonResponse));
        }
Пример #2
0
        public async Task <string> GetDbTimeAsync()
        {
            await Task.Delay(100);

            FailGenerator.FailIfNeeded(1);

            var apiFullUrl = $"{timeApiUrl}/api/time/dbtime";

            return(await httpClientFactory.CreateClient().GetStringAsync(apiFullUrl));
        }
        public string GetLocalDay()
        {
            FailGenerator.FailIfNeeded(1);

            if (logger.IsEnabled(LogLevel.Debug))
            {
                LogRequestHeaders();
            }

            var result = DateTime.Now.DayOfWeek.ToString();

            logger.LogInformation("Retrieved current day is {currentDay} at {time}", result, DateTime.UtcNow);
            return(result);
        }
        public async Task <DateTime> GetDbTimeAsync()
        {
            FailGenerator.FailIfNeeded(1);

            if (logger.IsEnabled(LogLevel.Debug))
            {
                LogRequestHeaders();
            }

            var result = await repository.GetTimeFromSqlAsync();

            logger.LogInformation("{operation} result is {result}", nameof(repository.GetTimeFromSqlAsync), result);

            return(result);
        }
        public async Task <DateTime> GetDbTimeAsync()
        {
            FailGenerator.FailIfNeeded(1);

            if (logger.IsEnabled(LogLevel.Debug))
            {
                LogRequestHeaders();
            }

            var result = await repository.GetTimeFromSqlAsync();

            logger.LogInformation("Retrieved db time: delta to local is {delta}ms", Math.Abs(DateTime.UtcNow.Subtract(result).TotalMilliseconds));

            return(result);
        }
Пример #6
0
        public async Task <DateTime> GetTimeFromSqlAsync()
        {
            var span = this.tracer.StartSpan(nameof(GetTimeFromSqlAsync), SpanKind.Client);

            try
            {
                FailGenerator.FailIfNeeded(1);

                return(await this.repository.GetTimeFromSqlAsync());
            }
            catch (Exception ex)
            {
                span.Status = Status.Internal.WithDescription(ex.ToString());
                throw;
            }
            finally
            {
                span.End();
            }
        }