/// <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> /// Store the given <see cref="T:Quartz.IJobDetail"/>. /// </summary> /// <param name="jobDetail">The <see cref="T:Quartz.IJobDetail"/> to be stored.</param><param name="replaceExisting">If <see langword="true"/>, any <see cref="T:Quartz.IJob"/> existing in the /// <see cref="T:Quartz.Spi.IJobStore"/> with the same name and group should be /// over-written. /// </param> public override void StoreJob(IJobDetail jobDetail, bool replaceExisting) { var jobHashKey = RedisJobStoreSchema.JobHashKey(jobDetail.Key); var jobDataMapHashKey = RedisJobStoreSchema.JobDataMapHashKey(jobDetail.Key); var jobGroupSetKey = RedisJobStoreSchema.JobGroupSetKey(jobDetail.Key.Group); if (Db.KeyExists(jobHashKey) && !replaceExisting) { throw new ObjectAlreadyExistsException(jobDetail); } Db.HashSet(jobHashKey, ConvertToHashEntries(jobDetail)); Db.HashSet(jobDataMapHashKey, ConvertToHashEntries(jobDetail.JobDataMap)); Db.SetAdd(RedisJobStoreSchema.JobsSetKey(), jobHashKey); Db.SetAdd(RedisJobStoreSchema.JobGroupsSetKey(), jobGroupSetKey); Db.SetAdd(jobGroupSetKey, jobHashKey); }
/// <summary> /// Pause the <see cref="T:Quartz.IJob"/> with the given key - by /// pausing all of its current <see cref="T:Quartz.ITrigger"/>s. /// </summary> public override IList <string> PauseJobs(GroupMatcher <JobKey> matcher) { var pausedJobGroups = new List <string>(); if (matcher.CompareWithOperator.Equals(StringOperator.Equality)) { var jobGroupSetKey = RedisJobStoreSchema.JobGroupSetKey(matcher.CompareToValue); if (Db.SetAdd(RedisJobStoreSchema.PausedJobGroupsSetKey(), jobGroupSetKey)) { pausedJobGroups.Add(RedisJobStoreSchema.JobGroup(jobGroupSetKey)); foreach (RedisValue val in Db.SetMembers(jobGroupSetKey)) { PauseJob(RedisJobStoreSchema.JobKey(val)); } } } else { var jobGroupSets = Db.SetMembers(RedisJobStoreSchema.JobGroupsSetKey()); var jobGroups = jobGroupSets.Where(jobGroupSet => matcher.CompareWithOperator.Evaluate(RedisJobStoreSchema.JobGroup(jobGroupSet), matcher.CompareToValue)).ToDictionary <RedisValue, string, RedisValue[]>(jobGroupSet => jobGroupSet, jobGroupSet => Db.SetMembers(jobGroupSet.ToString())); foreach (var jobGroup in jobGroups) { if (Db.SetAdd(RedisJobStoreSchema.PausedJobGroupsSetKey(), jobGroup.Key)) { pausedJobGroups.Add(RedisJobStoreSchema.JobGroup(jobGroup.Key)); foreach (var jobHashKey in jobGroup.Value) { PauseJob(RedisJobStoreSchema.JobKey(jobHashKey)); } } } } return(pausedJobGroups); }
/// <summary> /// Resume (un-pause) all of the <see cref="T:Quartz.IJob"/>s in /// the given group. /// <para> /// If any of the <see cref="T:Quartz.IJob"/> s had <see cref="T:Quartz.ITrigger"/> s that /// missed one or more fire-times, then the <see cref="T:Quartz.ITrigger"/>'s /// misfire instruction will be applied. /// </para> /// </summary> public override global::Quartz.Collection.ISet <string> ResumeJobs(GroupMatcher <JobKey> matcher) { var resumedJobGroups = new List <string>(); if (matcher.CompareWithOperator.Equals(StringOperator.Equality)) { var jobGroupSetKey = RedisJobStoreSchema.JobGroupSetKey(matcher.CompareToValue); var removedPausedResult = Db.SetRemove(RedisJobStoreSchema.PausedJobGroupsSetKey(), jobGroupSetKey); var jobsResult = Db.SetMembers(jobGroupSetKey); if (removedPausedResult) { resumedJobGroups.Add(RedisJobStoreSchema.JobGroup(jobGroupSetKey)); } foreach (var job in jobsResult) { ResumeJob(RedisJobStoreSchema.JobKey(job)); } } else { foreach (var jobGroupSetKey in Db.SetMembers(RedisJobStoreSchema.JobGroupsSetKey())) { if (matcher.CompareWithOperator.Evaluate(RedisJobStoreSchema.JobGroup(jobGroupSetKey), matcher.CompareToValue)) { resumedJobGroups.AddRange(ResumeJobs( GroupMatcher <JobKey> .GroupEquals(RedisJobStoreSchema.JobGroup(jobGroupSetKey)))); } } } return(new global::Quartz.Collection.HashSet <string>(resumedJobGroups)); }