protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var time = DateTime.UtcNow; logger.LogInformation($"Start settling use cycle at {time}.."); await provider.WithDbContext(async dbContext => { foreach (var i in dbContext.UseCycleEntries) { if (time >= service.NextDue(i.LastSettled)) { logger.LogInformation($"Settling use cycle for {i}"); if (service.TrySettle(i)) { await dbContext.SaveChangesAsync(); } } else { logger.LogInformation($"Will not settle use cycle {i} this time."); } } }); logger.LogInformation("End settling use cycle."); await Task.Delay(configuration.CheckCycleMs, stoppingToken); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var time = DateTime.UtcNow; logger.LogInformation($"Start charging management fees at {time}.."); await provider.WithDbContext(async dbContext => { var system = await dbContext.Systems.FirstAsync(); foreach (var i in dbContext.ManagementFeeEntries) { if (time >= service.NextDue(i.LastSettled)) { logger.LogInformation($"{i} is being charged with management fee."); service.TrySettle(system, i); logger.LogInformation($"Charging {i} for management fee is completed."); await dbContext.SaveChangesAsync(); } else { logger.LogInformation($"{i} will not be charged with management fee this time."); } } }); logger.LogInformation("End charging management fee."); await Task.Delay(configuration.CheckCycleMs, stoppingToken); } }