コード例 #1
0
        /// <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));
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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);
        }