Example #1
0
        /// <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);
                }
            }
        }
Example #2
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));
        }
Example #3
0
        /// <summary>
        /// Remove (delete) the <see cref="T:Quartz.ICalendar"/> with the
        ///             given name.
        /// </summary>
        /// <remarks>
        /// If removal of the <see cref="T:Quartz.ICalendar"/> would result in
        ///             <see cref="T:Quartz.ITrigger"/>s pointing to non-existent calendars, then a
        ///             <see cref="T:Quartz.JobPersistenceException"/> will be thrown.
        /// </remarks>
        /// <param name="calendarName">The name of the <see cref="T:Quartz.ICalendar"/> to be removed.</param>
        /// <returns>
        /// <see langword="true"/> if a <see cref="T:Quartz.ICalendar"/> with the given name
        ///             was found and removed from the store.
        /// </returns>
        public override bool RemoveCalendar(string calendarName)
        {
            var calendarTriggersSetKey = RedisJobStoreSchema.CalendarTriggersSetKey(calendarName);

            if (Db.SetLength(calendarTriggersSetKey) > 0)
            {
                throw new JobPersistenceException(string.Format("There are triggers are using calendar {0}",
                                                                calendarName));
            }

            var calendarHashKey = RedisJobStoreSchema.CalendarHashKey(calendarName);

            return(Db.KeyDelete(calendarHashKey) && Db.SetRemove(RedisJobStoreSchema.CalendarsSetKey(), calendarHashKey));
        }
Example #4
0
        /// <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);
        }