/// <summary> /// Store the given <see cref="T:Quartz.ICalendar"/>. /// </summary> /// <param name="name">The name.</param><param name="calendar">The <see cref="T:Quartz.ICalendar"/> to be stored.</param><param name="replaceExisting">If <see langword="true"/>, any <see cref="T:Quartz.ICalendar"/> existing /// in the <see cref="T:Quartz.Spi.IJobStore"/> with the same name and group /// should be over-written.</param><param name="updateTriggers">If <see langword="true"/>, any <see cref="T:Quartz.ITrigger"/>s existing /// in the <see cref="T:Quartz.Spi.IJobStore"/> that reference an existing /// Calendar with the same name with have their next fire time /// re-computed with the new <see cref="T:Quartz.ICalendar"/>.</param><throws>ObjectAlreadyExistsException </throws> public override void StoreCalendar(string name, ICalendar calendar, bool replaceExisting, bool updateTriggers) { string calendarHashKey = RedisJobStoreSchema.CalendarHashKey(name); if (replaceExisting == false && Db.KeyExists(calendarHashKey)) { throw new ObjectAlreadyExistsException(string.Format("Calendar with key {0} already exists", calendarHashKey)); } Db.HashSet(calendarHashKey, ConvertToHashEntries(calendar)); Db.SetAdd(RedisJobStoreSchema.CalendarsSetKey(), calendarHashKey); if (updateTriggers) { var calendarTriggersSetkey = RedisJobStoreSchema.CalendarTriggersSetKey(name); var triggerHashKeys = Db.SetMembers(calendarTriggersSetkey); foreach (var triggerHashKey in triggerHashKeys) { var trigger = RetrieveTrigger(RedisJobStoreSchema.TriggerKey(triggerHashKey)); trigger.UpdateWithNewCalendar(calendar, TimeSpan.FromSeconds(MisfireThreshold)); StoreTrigger(trigger, true); } } }
/// <summary> /// remove the trigger from all the possible state in the its respective sorted set. /// </summary> /// <param name="triggerHashKey">trigger hash key</param> /// <returns>succeeds or not</returns> public override bool UnsetTriggerState(string triggerHashKey) { var removedList = (from RedisTriggerState state in Enum.GetValues(typeof(RedisTriggerState)) select Db.SortedSetRemove(RedisJobStoreSchema.TriggerStateSetKey(state), triggerHashKey)).ToList(); if (removedList.Any(x => x)) { return(Db.KeyDelete( RedisJobStoreSchema.TriggerLockKey(RedisJobStoreSchema.TriggerKey(triggerHashKey)))); } return(false); }
/// <summary> /// Remove (delete) the <see cref="T:Quartz.IJob"/> with the given /// key, and any <see cref="T:Quartz.ITrigger"/> s that reference /// it. /// </summary> /// <remarks> /// If removal of the <see cref="T:Quartz.IJob"/> results in an empty group, the /// group should be removed from the <see cref="T:Quartz.Spi.IJobStore"/>'s list of /// known group names. /// </remarks> /// <returns> /// <see langword="true"/> if a <see cref="T:Quartz.IJob"/> with the given name and /// group was found and removed from the store. /// </returns> public override bool RemoveJob(JobKey jobKey) { var jobHashKey = RedisJobStoreSchema.JobHashKey(jobKey); var jobDataMapHashKey = RedisJobStoreSchema.JobDataMapHashKey(jobKey); var jobGroupSetKey = RedisJobStoreSchema.JobGroupSetKey(jobKey.Group); var jobTriggerSetKey = RedisJobStoreSchema.JobTriggersSetKey(jobKey); var delJobHashKeyResult = Db.KeyDelete(jobHashKey); Db.KeyDelete(jobDataMapHashKey); Db.SetRemove(RedisJobStoreSchema.JobsSetKey(), jobHashKey); Db.SetRemove(jobGroupSetKey, jobHashKey); var jobTriggerSetResult = Db.SetMembers(jobTriggerSetKey); Db.KeyDelete(jobTriggerSetKey); var jobGroupSetLengthResult = Db.SetLength(jobGroupSetKey); if (jobGroupSetLengthResult == 0) { Db.SetRemoveAsync(RedisJobStoreSchema.JobGroupsSetKey(), jobGroupSetKey); } // remove all triggers associated with this job foreach (var triggerHashKey in jobTriggerSetResult) { var triggerkey = RedisJobStoreSchema.TriggerKey(triggerHashKey); var triggerGroupKey = RedisJobStoreSchema.TriggerGroupSetKey(triggerkey.Group); this.UnsetTriggerState(triggerHashKey); Db.SetRemove(RedisJobStoreSchema.TriggersSetKey(), triggerHashKey); Db.SetRemove(RedisJobStoreSchema.TriggerGroupsSetKey(), triggerGroupKey); Db.SetRemove(RedisJobStoreSchema.TriggerGroupSetKey(triggerkey.Group), triggerHashKey); Db.KeyDelete(triggerHashKey.ToString()); } return(delJobHashKeyResult); }
/// <summary> /// Resume (un-pause) all of the <see cref="T:Quartz.ITrigger"/>s /// in the given group. /// <para> /// If any <see cref="T:Quartz.ITrigger"/> missed one or more fire-times, then the /// <see cref="T:Quartz.ITrigger"/>'s misfire instruction will be applied. /// </para> /// </summary> public override IList <string> ResumeTriggers(GroupMatcher <TriggerKey> matcher) { var resumedTriggerGroups = new List <string>(); if (matcher.CompareWithOperator.Equals(StringOperator.Equality)) { var triggerGroupSetKey = RedisJobStoreSchema.TriggerGroupSetKey(matcher.CompareToValue); Db.SetRemove(RedisJobStoreSchema.PausedTriggerGroupsSetKey(), triggerGroupSetKey); var triggerHashKeysResult = Db.SetMembers(triggerGroupSetKey); foreach (var triggerHashKey in triggerHashKeysResult) { var trigger = RetrieveTrigger(RedisJobStoreSchema.TriggerKey(triggerHashKey)); ResumeTrigger(trigger.Key); if (!resumedTriggerGroups.Contains(trigger.Key.Group)) { resumedTriggerGroups.Add(trigger.Key.Group); } } } else { foreach (var triggerGroupSetKy in Db.SetMembersAsync(RedisJobStoreSchema.TriggerGroupsSetKey()).Result) { if (matcher.CompareWithOperator.Evaluate(RedisJobStoreSchema.TriggerGroup(triggerGroupSetKy), matcher.CompareToValue)) { resumedTriggerGroups.AddRange(ResumeTriggers(GroupMatcher <TriggerKey> .GroupEquals(RedisJobStoreSchema.TriggerGroup(triggerGroupSetKy)))); } } } return(resumedTriggerGroups); }