Ejemplo n.º 1
0
        public Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = new CancellationToken())
        {
            var lastProcessTime = WorkerStatistics.GetLastProcessTime();
            var timeAgo         = DateTimeOffset.UtcNow.Subtract(lastProcessTime);

            return(Task.FromResult(lastProcessTime > DateTime.Now.AddSeconds(-90)
                ? HealthCheckResult.Healthy("Processing Healthy")
                : HealthCheckResult.Unhealthy("Not healthy.")));
        }
Ejemplo n.º 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            int i = 0;

            while (!stoppingToken.IsCancellationRequested)
            {
                if (i < 10)
                {
                    _logger.LogInformation($"I'm doing Teller Work at {DateTimeOffset.Now:O}");
                    WorkerStatistics.SetProcessTime();
                    i++;
                }
                else
                {
                    _logger.LogError($"Uh oh! Haven't Processed for {DateTimeOffset.Now.Subtract(WorkerStatistics.GetLastProcessTime()).TotalSeconds} seconds!");
                }
                await Task.Delay(TimeSpan.FromSeconds(2), stoppingToken);
            }
        }