public List <TriggerKey> GetTriggersToAcquire(DateTimeOffset noLaterThan, DateTimeOffset noEarlierThan, int maxCount) { if (maxCount < 1) { maxCount = 1; } var noLaterThanDateTime = noLaterThan.UtcDateTime; var noEarlierThanDateTime = noEarlierThan.UtcDateTime; return(Collection.Find(trigger => trigger.Id.InstanceName == InstanceName && trigger.State == Models.TriggerState.Waiting && trigger.NextFireTime <= noLaterThanDateTime && (trigger.MisfireInstruction == -1 || (trigger.MisfireInstruction != -1 && trigger.NextFireTime >= noEarlierThanDateTime))) .Sort(SortBuilder.Combine( SortBuilder.Ascending(trigger => trigger.NextFireTime), SortBuilder.Descending(trigger => trigger.Priority) )) .Limit(maxCount) .Project(trigger => trigger.Id.GetTriggerKey()) .ToList()); }
/// <summary> /// Get the names of all of the triggers in the given state that have /// misfired - according to the given timestamp. No more than count will /// be returned. /// </summary> /// <param name="nextFireTime"></param> /// <param name="maxResults"></param> /// <param name="results"></param> /// <returns></returns> public bool HasMisfiredTriggers(DateTime nextFireTime, int maxResults, out List <TriggerKey> results) { var cursor = Collection.Find( trigger => trigger.Id.InstanceName == InstanceName && trigger.MisfireInstruction != MisfireInstruction.IgnoreMisfirePolicy && trigger.NextFireTime < nextFireTime && trigger.State == Models.TriggerState.Waiting) .Project(trigger => trigger.Id.GetTriggerKey()) .Sort(SortBuilder.Combine( SortBuilder.Ascending(trigger => trigger.NextFireTime), SortBuilder.Descending(trigger => trigger.Priority) )).ToCursor(); results = new List <TriggerKey>(); var hasReachedLimit = false; while (cursor.MoveNext() && !hasReachedLimit) { foreach (var triggerKey in cursor.Current) { if (results.Count == maxResults) { hasReachedLimit = true; } else { results.Add(triggerKey); } } } return(hasReachedLimit); }