private string ComputeMaxSnapshotCount(SnapshotRule rule) { var nextFireTime = rule.GetNextFireTime(DateTimeOffset.Now.AddSeconds(-1)); if (!nextFireTime.HasValue) { return("0"); } var lastFireTime = nextFireTime.Value.AddSeconds(rule.GetLifeTimeSeconds()); CancellationTokenSource cancelSrc = new CancellationTokenSource(); CancellationToken cancelToken = cancelSrc.Token; Task <int> computeTask = Task.Run(() => rule.GetFireCountBetween(nextFireTime.Value, lastFireTime, cancelToken)); try { cancelSrc.CancelAfter(1000); computeTask.Wait(cancelToken); return(computeTask.Result.ToString()); } catch (OperationCanceledException) { return("(timeout: too many)"); } }
private IEnumerable <SnapshotInstance> GetPruningListForRule(SnapshotRule rule) { List <SnapshotInstance> instances = SnapshotRuleInstanceMap.SafeGet(rule.Id); if (instances == null) { return(new List <SnapshotInstance>()); } long lifetime = rule.GetLifeTimeSeconds(); return(instances.Where(i => i.CreatedAt.AddSeconds(lifetime) < DateTime.Now).ToList()); }