/// <summary> /// Remove (delete) the <see cref="T:Quartz.ITrigger"/> with the given key. /// </summary> /// <remarks> /// <para> /// If removal of the <see cref="T:Quartz.ITrigger"/> results in an empty group, the /// group should be removed from the <see cref="T:Quartz.Spi.IJobStore"/>'s list of /// known group names. /// </para> /// <para> /// If removal of the <see cref="T:Quartz.ITrigger"/> results in an 'orphaned' <see cref="T:Quartz.IJob"/> /// that is not 'durable', then the <see cref="T:Quartz.IJob"/> should be deleted /// also. /// </para> /// </remarks> /// <returns> /// <see langword="true"/> if a <see cref="T:Quartz.ITrigger"/> with the given /// name and group was found and removed from the store. /// </returns> public override bool RemoveTrigger(TriggerKey triggerKey, bool removeNonDurableJob = true) { var triggerHashKey = RedisJobStoreSchema.TriggerHashkey(triggerKey); if (!Db.KeyExists(triggerHashKey)) { return(false); } IOperableTrigger trigger = RetrieveTrigger(triggerKey); var triggerGroupSetKey = RedisJobStoreSchema.TriggerGroupSetKey(triggerKey.Group); var jobHashKey = RedisJobStoreSchema.JobHashKey(trigger.JobKey); var jobTriggerSetkey = RedisJobStoreSchema.JobTriggersSetKey(trigger.JobKey); Db.SetRemove(RedisJobStoreSchema.TriggersSetKey(), triggerHashKey); Db.SetRemove(triggerGroupSetKey, triggerHashKey); Db.SetRemove(jobTriggerSetkey, triggerHashKey); if (Db.SetLength(triggerGroupSetKey) == 0) { Db.SetRemove(RedisJobStoreSchema.TriggerGroupsSetKey(), triggerGroupSetKey); } if (removeNonDurableJob) { var jobTriggerSetKeyLengthResult = Db.SetLength(jobTriggerSetkey); var jobExistsResult = Db.KeyExists(jobHashKey); if (jobTriggerSetKeyLengthResult == 0 && jobExistsResult) { var job = RetrieveJob(trigger.JobKey); if (job.Durable == false) { RemoveJob(job.Key); SchedulerSignaler.NotifySchedulerListenersJobDeleted(job.Key); } } } if (!string.IsNullOrEmpty(trigger.CalendarName)) { Db.SetRemove(RedisJobStoreSchema.CalendarTriggersSetKey(trigger.CalendarName), triggerHashKey); } this.UnsetTriggerState(triggerHashKey); return(Db.KeyDelete(triggerHashKey)); }
/// <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) the <see cref="T:Quartz.ITrigger"/> with the /// given key. /// <para> /// If the <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> /// <seealso cref="T:System.String"/> public override void ResumeTrigger(TriggerKey triggerKey) { var triggerHashKey = RedisJobStoreSchema.TriggerHashkey(triggerKey); var triggerExists = Db.SetContains(RedisJobStoreSchema.TriggersSetKey(), triggerHashKey); var isPausedTrigger = Db.SortedSetScore(RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Paused), triggerHashKey); var isPausedBlockedTrigger = Db.SortedSetScore(RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.PausedBlocked), triggerHashKey); if (triggerExists == false) { return; } //Trigger is not paused, cant be resumed then. if (!isPausedTrigger.HasValue && !isPausedBlockedTrigger.HasValue) { return; } var trigger = RetrieveTrigger(triggerKey); var jobHashKey = RedisJobStoreSchema.JobHashKey(trigger.JobKey); var nextFireTime = trigger.GetNextFireTimeUtc(); if (nextFireTime.HasValue) { if (Db.SetContains(RedisJobStoreSchema.BlockedJobsSet(), jobHashKey)) { SetTriggerState(RedisTriggerState.Blocked, nextFireTime.Value.DateTime.ToUnixTimeMilliSeconds(), triggerHashKey); } else { SetTriggerState(RedisTriggerState.Waiting, nextFireTime.Value.DateTime.ToUnixTimeMilliSeconds(), triggerHashKey); } } ApplyMisfire(trigger); }
/// <summary> /// Store the given <see cref="T:Quartz.ITrigger"/>. /// </summary> /// <param name="trigger">The <see cref="T:Quartz.ITrigger"/> to be stored.</param><param name="replaceExisting">If <see langword="true"/>, any <see cref="T:Quartz.ITrigger"/> existing in /// the <see cref="T:Quartz.Spi.IJobStore"/> with the same name and group should /// be over-written.</param><throws>ObjectAlreadyExistsException </throws> public override void StoreTrigger(ITrigger trigger, bool replaceExisting) { var triggerHashKey = RedisJobStoreSchema.TriggerHashkey(trigger.Key); var triggerGroupSetKey = RedisJobStoreSchema.TriggerGroupSetKey(trigger.Key.Group); var jobTriggerSetKey = RedisJobStoreSchema.JobTriggersSetKey(trigger.JobKey); if (((trigger is ISimpleTrigger) == false) && ((trigger is ICronTrigger) == false)) { throw new NotImplementedException("Unknown trigger, only SimpleTrigger and CronTrigger are supported"); } var triggerExists = Db.KeyExists(triggerHashKey); if (triggerExists && replaceExisting == false) { throw new ObjectAlreadyExistsException(trigger); } Db.HashSet(triggerHashKey, ConvertToHashEntries(trigger)); Db.SetAdd(RedisJobStoreSchema.TriggersSetKey(), triggerHashKey); Db.SetAdd(RedisJobStoreSchema.TriggerGroupsSetKey(), triggerGroupSetKey); Db.SetAdd(triggerGroupSetKey, triggerHashKey); Db.SetAdd(jobTriggerSetKey, triggerHashKey); if (!string.IsNullOrEmpty(trigger.CalendarName)) { var calendarTriggersSetKey = RedisJobStoreSchema.CalendarTriggersSetKey(trigger.CalendarName); Db.SetAdd(calendarTriggersSetKey, triggerHashKey); } //if trigger already exists, remove it from all the possible states. if (triggerExists) { this.UnsetTriggerState(triggerHashKey); } //then update it with the new state in the its respectvie sorted set. UpdateTriggerState(trigger); }