public async Task CheckUsagesAsync() { var today = DateTime.Today; foreach (var kvp in state.Value.Targets) { var target = kvp.Value; var from = GetFromDate(today, target.NumDays); if (!target.Triggered.HasValue || target.Triggered < from) { var usage = await usageTracker.GetMonthlyCallsAsync(target.AppId.Id.ToString(), today); var limit = kvp.Value.Limits; if (usage > limit) { kvp.Value.Triggered = today; var @event = new AppUsageExceeded { AppId = target.AppId, CallsCurrent = usage, CallsLimit = limit, RuleId = kvp.Key }; await state.WriteEventAsync(Envelope.Create <IEvent>(@event)); } } } await state.WriteAsync(); }
public async Task CheckUsagesAsync() { var today = DateTime.Today; foreach (var(key, target) in state.Value.Targets) { var from = GetFromDate(today, target.NumDays); if (target.Triggered == null || target.Triggered < from) { var costs = await usageTracker.GetMonthCallsAsync(target.AppId.Id.ToString(), today, null); var limit = target.Limits; if (costs > limit) { target.Triggered = today; var @event = new AppUsageExceeded { AppId = target.AppId, CallsCurrent = costs, CallsLimit = limit, RuleId = key }; await state.WriteEventAsync(Envelope.Create <IEvent>(@event)); } } } await state.WriteAsync(); }