public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (nominalType != typeof(TriggerKey) || actualType != typeof(TriggerKey))
            {
                var message = string.Format("Can't deserialize a {0} from {1}.", nominalType.FullName, this.GetType().Name);
                throw new BsonSerializationException(message);
            }

            var bsonType = bsonReader.CurrentBsonType;
            if (bsonType == BsonType.Document)
            {
                TriggerKey item;
                
                bsonReader.ReadStartDocument();
                item = new TriggerKey(
                    bsonReader.ReadString("Name"),
                    bsonReader.ReadString("Group"));
                bsonReader.ReadEndDocument();

                return item;
            }
            else if (bsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
                throw new BsonSerializationException(message);
            }
        }
Beispiel #2
0
        public override bool OnStart()
        {
            Trace.WriteLine("WorkerRole1 Run", "Information");

            var properties = new NameValueCollection();
            properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
            properties["quartz.jobStore.dataSource"] = "default";
            properties["quartz.jobStore.clustered"] = "true";
            properties["quartz.jobStore.selectWithLockSQL"] = string.Format(CultureInfo.InvariantCulture, "SELECT * FROM {0}{1} WHERE {2} = {3} AND {4} = @lockName", new object[] { "{0}", "LOCKS", "SCHED_NAME", "{1}", "LOCK_NAME" });
            properties["quartz.jobStore.acquireTriggersWithinLock"] = "true";
            properties["quartz.scheduler.instanceId"] = "AUTO";
            properties["quartz.threadPool.threadCount"] = "1";
            properties["quartz.jobStore.tablePrefix"] = "Scheduling.";
            properties["quartz.dataSource.default.connectionString"] = @"Server = (local)\sqlexpress; Database = DB; Integrated Security = True";
            properties["quartz.dataSource.default.provider"] = "SqlServer-20";

            var scheduler = new StdSchedulerFactory(properties).GetScheduler();
            scheduler.Clear();

            var triggerKey = new TriggerKey("t1");
            var trigger = scheduler.GetTrigger(triggerKey);

            var jobBuilder = JobBuilder.Create<Job>();
            var job = jobBuilder.Build();

            var t = scheduler.GetTrigger(new TriggerKey("t1"));

            trigger = new SimpleTriggerImpl("t1", 100000, TimeSpan.FromSeconds(5));

            scheduler.ScheduleJob(job, trigger);

            scheduler.Start();

            return base.OnStart();
        }
        public TriggerPropertyBundle LoadExtendedTriggerProperties(ConnectionAndTransactionHolder conn, TriggerKey triggerKey)
        {
            using (IDbCommand cmd = CommandAccessor.PrepareCommand(conn, AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlSelectSimpleTrigger, TablePrefix, SchedNameLiteral)))
            {
                CommandAccessor.AddCommandParameter(cmd, "triggerName", triggerKey.Name);
                CommandAccessor.AddCommandParameter(cmd, "triggerGroup", triggerKey.Group);

                using (IDataReader rs = cmd.ExecuteReader())
                {
                    if (rs.Read())
                    {
                        int repeatCount = rs.GetInt32(AdoConstants.ColumnRepeatCount);
                        long repeatInterval = rs.GetInt64(AdoConstants.ColumnRepeatInterval);
                        int timesTriggered = rs.GetInt32(AdoConstants.ColumnTimesTriggered);

                        SimpleScheduleBuilder sb = SimpleScheduleBuilder.Create()
                            .WithRepeatCount(repeatCount)
                            .WithInterval(TimeSpan.FromMilliseconds(repeatInterval));

                        string[] statePropertyNames = {"timesTriggered"};
                        object[] statePropertyValues = {timesTriggered};

                        return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues);
                    }
                }
                throw new InvalidOperationException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlSelectSimpleTrigger, TablePrefix, SchedNameLiteral));
            }
        }
        public TriggerPropertyBundle LoadExtendedTriggerProperties(ConnectionAndTransactionHolder conn, TriggerKey triggerKey)
        {
            using (IDbCommand cmd = CommandAccessor.PrepareCommand(conn, AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlSelectCronTriggers, TablePrefix, SchedNameLiteral)))
            {
                CommandAccessor.AddCommandParameter(cmd, "triggerName", triggerKey.Name);
                CommandAccessor.AddCommandParameter(cmd, "triggerGroup", triggerKey.Group);

                using (IDataReader rs = cmd.ExecuteReader())
                {
                    if (rs.Read())
                    {
                        string cronExpr = rs.GetString(AdoConstants.ColumnCronExpression);
                        string timeZoneId = rs.GetString(AdoConstants.ColumnTimeZoneId);

                        CronScheduleBuilder cb = CronScheduleBuilder.CronSchedule(cronExpr);
  
                        if (timeZoneId != null)
                        {
                            cb.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById(timeZoneId));
                        }

                        return new TriggerPropertyBundle(cb, null, null);
                    }
                }

                throw new InvalidOperationException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlSelectCronTriggers, TablePrefix, SchedNameLiteral));
            }
        }
 public void RemoveSchedule(Schedule schedule)
 {
     var triggerKey = new TriggerKey(schedule.Id.ToString(), schedule.CommandId.ToString());
     var jobKey = new JobKey(schedule.Id.ToString(), schedule.CommandId.ToString());
     scheduler.UnscheduleJob(triggerKey);
     scheduler.DeleteJob(jobKey);
 }
 public void PostRestartTrigger(string key)
 {
     var triggerKey = new TriggerKey(key);
     var trigger = _scheduler.GetTrigger(triggerKey);
     if (trigger == null)
         throw new HttpResponseException(HttpStatusCode.NotFound);
     _scheduler.ResumeTrigger(triggerKey);
 }
 public ExampleTrigger(TriggerKey key, DateTime startTimeRetryUtc, DateTime? endTimeRetryUtc, int v, TimeSpan zero)
 {
     this._key = key;
     this._startTimeRetryUtc = startTimeRetryUtc;
     this._endTimeRetryUtc = endTimeRetryUtc;
     this._v = v;
     this._zero = zero;
 }
Beispiel #8
0
        public void TriggerKeyShouldBeSerializable()
        {
            TriggerKey original = new TriggerKey("name", "group");

            TriggerKey cloned = original.DeepClone();

            Assert.That(cloned.Name, Is.EqualTo(original.Name));
            Assert.That(cloned.Group, Is.EqualTo(original.Group));
        }
        public int DeleteExtendedTriggerProperties(ConnectionAndTransactionHolder conn, TriggerKey triggerKey)
        {
            using (IDbCommand cmd = DbAccessor.PrepareCommand(conn, AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlDeleteCronTrigger, TablePrefix, SchedNameLiteral)))
            {
                DbAccessor.AddCommandParameter(cmd, "triggerName", triggerKey.Name);
                DbAccessor.AddCommandParameter(cmd, "triggerGroup", triggerKey.Group);

                return cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        /// Get the current state of the identified <see cref="T:Quartz.ITrigger"/>.
        /// </summary>
        /// <seealso cref="T:Quartz.TriggerState"/>
        public override TriggerState GetTriggerState(TriggerKey triggerKey)
        {
            var triggerHashKey = this.RedisJobStoreSchema.TriggerHashkey(triggerKey);

            if (
                this.Db.SortedSetScore(this.RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Paused),
                                        triggerHashKey) != null ||
                this.Db.SortedSetScore(this.RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.PausedBlocked),
                                        triggerHashKey) != null)
            {
                return TriggerState.Paused;
            }
            if (
                this.Db.SortedSetScore(this.RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Blocked), triggerHashKey) != null)
            {
                return TriggerState.Blocked;
            }
            if (
                this.Db.SortedSetScore(this.RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Waiting),
                                       triggerHashKey) != null || this.Db.SortedSetScore(this.RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Acquired),triggerHashKey) !=null)
            {
                return TriggerState.Normal;
            }
            if (
                this.Db.SortedSetScore(this.RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Completed),
                                       triggerHashKey) != null)
            {
                return TriggerState.Complete;
            }
            if (
                this.Db.SortedSetScore(this.RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Error), triggerHashKey)
                != null)
            {
                return TriggerState.Error;
            }

            return TriggerState.None;
        }
Beispiel #11
0
        ITrigger CreateTrigger(RecurringSchedule schedule, IJobDetail jobDetail, TriggerKey triggerKey)
        {
            var tz = TimeZoneInfo.Local;

            if (!string.IsNullOrWhiteSpace(schedule.TimeZoneId) && schedule.TimeZoneId != tz.Id)
            {
                tz = TimeZoneInfo.FindSystemTimeZoneById(schedule.TimeZoneId);
            }

            var triggerBuilder = TriggerBuilder.Create()
                                 .ForJob(jobDetail)
                                 .WithIdentity(triggerKey)
                                 .StartAt(schedule.StartTime)
                                 .WithDescription(schedule.Description)
                                 .WithCronSchedule(schedule.CronExpression, x =>
            {
                x.InTimeZone(tz);
                switch (schedule.MisfirePolicy)
                {
                case MissedEventPolicy.Skip:
                    x.WithMisfireHandlingInstructionDoNothing();
                    break;

                case MissedEventPolicy.Send:
                    x.WithMisfireHandlingInstructionFireAndProceed();
                    break;
                }
            });

            if (schedule.EndTime.HasValue)
            {
                triggerBuilder.EndAt(schedule.EndTime);
            }

            return(triggerBuilder.Build());
        }
Beispiel #12
0
        public async Task Consume(ConsumeContext <ScheduleRecurringMessage> context)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("ScheduleRecurringMessage: {0} at {1}", context.Message.CorrelationId, context.Message.Schedule.ScheduleId);
            }

            var jobKey = new JobKey(context.Message.Schedule.ScheduleId, context.Message.Schedule.ScheduleGroup);

            var jobDetail = await CreateJobDetail(context, context.Message.Destination, jobKey).ConfigureAwait(false);

            var triggerKey = new TriggerKey("Recurring.Trigger." + context.Message.Schedule.ScheduleId, context.Message.Schedule.ScheduleGroup);

            var trigger = CreateTrigger(context.Message.Schedule, jobDetail, triggerKey);

            if (_scheduler.CheckExists(triggerKey))
            {
                _scheduler.RescheduleJob(triggerKey, trigger);
            }
            else
            {
                _scheduler.ScheduleJob(jobDetail, trigger);
            }
        }
Beispiel #13
0
        public async Task <TriggerPropertyBundle> LoadExtendedTriggerProperties(
            ConnectionAndTransactionHolder conn,
            TriggerKey triggerKey,
            CancellationToken cancellationToken = default)
        {
            using (var cmd = DbAccessor.PrepareCommand(conn, AdoJobStoreUtil.ReplaceTablePrefix(SelectSimplePropsTrigger, TablePrefix, SchedNameLiteral)))
            {
                DbAccessor.AddCommandParameter(cmd, "triggerName", triggerKey.Name);
                DbAccessor.AddCommandParameter(cmd, "triggerGroup", triggerKey.Group);

                using (var rs = await cmd.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false))
                {
                    if (await rs.ReadAsync(cancellationToken).ConfigureAwait(false))
                    {
                        SimplePropertiesTriggerProperties properties = new SimplePropertiesTriggerProperties();

                        properties.String1    = rs.GetString(ColumnStrProp1);
                        properties.String2    = rs.GetString(ColumnStrProp2);
                        properties.String3    = rs.GetString(ColumnStrProp3);
                        properties.Int1       = rs.GetInt32(ColumnIntProp1);
                        properties.Int2       = rs.GetInt32(ColumnIntProp2);
                        properties.Long1      = rs.GetInt64(ColumnLongProp1);
                        properties.Long2      = rs.GetInt64(ColumnLongProp2);
                        properties.Decimal1   = rs.GetDecimal(ColumnDecProp1);
                        properties.Decimal2   = rs.GetDecimal(ColumnDecProp2);
                        properties.Boolean1   = DbAccessor.GetBooleanFromDbValue(rs[ColumnBoolProp1]);
                        properties.Boolean2   = DbAccessor.GetBooleanFromDbValue(rs[ColumnBoolProp2]);
                        properties.TimeZoneId = rs.GetString(ColumnTimeZoneId);

                        return(GetTriggerPropertyBundle(properties));
                    }
                }
            }

            throw new InvalidOperationException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlSelectSimpleTrigger, TablePrefix, SchedNameLiteral));
        }
Beispiel #14
0
        public void ShouldGetJobDetailWhenCalledGetJobDetailOfTrigger()
        {
            // Arrange
            Guid     triggerId  = Guid.NewGuid();
            var      triggerKey = new TriggerKey("TestTrigger", "TestTriggerGroup");
            ITrigger trigger    = new SimpleTriggerImpl {
                JobKey = new JobKey("TestJob", "TestJobGroup")
            };

            _mockPersistanceStore.Setup(x => x.GetTriggerKey(triggerId)).Returns(triggerKey);
            _mockScheduler.Setup(x => x.GetTrigger(triggerKey)).Returns(trigger);
            _mockScheduler.Setup(i => i.GetJobDetail(trigger.JobKey)).Returns(new JobDetailImpl()
            {
                Key = trigger.JobKey, Group = "TestJobGroup"
            });

            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            var group = schedulerCore.GetJobDetailOfTrigger(triggerId).Key.Group;

            // Assert
            Assert.Equal("TestJobGroup", group);
        }
Beispiel #15
0
        /// <inheritdoc />
        public virtual async Task <IJobDetail?> SelectJobForTrigger(
            ConnectionAndTransactionHolder conn,
            TriggerKey triggerKey,
            ITypeLoadHelper loadHelper,
            bool loadJobType,
            CancellationToken cancellationToken = default)
        {
            using var cmd = PrepareCommand(conn, ReplaceTablePrefix(SqlSelectJobForTrigger));
            AddCommandParameter(cmd, "schedulerName", schedName);
            AddCommandParameter(cmd, "triggerName", triggerKey.Name);
            AddCommandParameter(cmd, "triggerGroup", triggerKey.Group);
            using var rs = await cmd.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false);

            if (await rs.ReadAsync(cancellationToken).ConfigureAwait(false))
            {
                JobDetailImpl job = new JobDetailImpl();
                job.Name    = rs.GetString(ColumnJobName) !;
                job.Group   = rs.GetString(ColumnJobGroup) !;
                job.Durable = GetBooleanFromDbValue(rs[ColumnIsDurable]);
                if (loadJobType)
                {
                    job.JobType = loadHelper.LoadType(rs.GetString(ColumnJobClass) !) !;
                }

                job.RequestsRecovery = GetBooleanFromDbValue(rs[ColumnRequestsRecovery]);

                return(job);
            }

            if (logger.IsDebugEnabled())
            {
                logger.Debug("No job for trigger '" + triggerKey + "'.");
            }

            return(null);
        }
Beispiel #16
0
        /// <summary>
        /// Produce the <see cref="ITrigger" />.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <returns>a Trigger that meets the specifications of the builder.</returns>
        public ITrigger Build()
        {
            if (scheduleBuilder == null)
            {
                scheduleBuilder = SimpleScheduleBuilder.Create();
            }
            IMutableTrigger trig = scheduleBuilder.Build();

            trig.CalendarName = calendarName;
            trig.Description = description;
            trig.StartTimeUtc = startTime;
            trig.EndTimeUtc = endTime;
            if (key == null)
            {
                key = new TriggerKey(Guid.NewGuid().ToString(), null);
            }
            trig.Key = key;
            if (jobKey != null)
            {
                trig.JobKey = jobKey;
            }
            trig.Priority = priority;

            if (!jobDataMap.IsEmpty)
            {
                trig.JobDataMap = jobDataMap;
            }

            return trig;
        }
Beispiel #17
0
 /// <summary>
 /// Use a TriggerKey with the given name and group to
 /// identify the Trigger.
 /// </summary>
 /// <remarks>
 /// <para>If none of the 'withIdentity' methods are set on the TriggerBuilder,
 /// then a random, unique TriggerKey will be generated.</para>
 /// </remarks>
 /// <param name="name">the name element for the Trigger's TriggerKey</param>
 /// <param name="group">the group element for the Trigger's TriggerKey</param>
 /// <returns>the updated TriggerBuilder</returns>
 /// <seealso cref="TriggerKey" />
 /// <seealso cref="ITrigger.Key" />
 public TriggerBuilder WithIdentity(string name, string group)
 {
     key = new TriggerKey(name, group);
     return this;
 }
        /// <summary>
        /// Remove (delete) the <see cref="ITrigger" /> with the
        /// given name.
        /// 
        /// </summary>
        /// <returns>
        /// 	<see langword="true" /> if a <see cref="ITrigger" /> with the given
        /// name and group was found and removed from the store.
        /// </returns>
        /// <param name="key">The <see cref="ITrigger" /> to be removed.</param>
        /// <param name="removeOrphanedJob">Whether to delete orpahaned job details from scheduler if job becomes orphaned from removing the trigger.</param>
        public virtual bool RemoveTrigger(TriggerKey key, bool removeOrphanedJob)
        {
            bool found;
            lock (lockObject)
            {
                var trigger = this.RetrieveTrigger(key);
                found = trigger != null;

                if (found)
                {
                    this.Triggers.Remove(
                        Query.EQ("_id", trigger.Key.ToBsonDocument()));

                    if (removeOrphanedJob)
                    {
                        IJobDetail jobDetail = this.RetrieveJob(trigger.JobKey);
                        IList<IOperableTrigger> trigs = this.GetTriggersForJob(jobDetail.Key);
                        if ((trigs == null
                                || trigs.Count == 0)
                            && !jobDetail.Durable)
                        {
                            if (this.RemoveJob(jobDetail.Key))
                            {
                                signaler.NotifySchedulerListenersJobDeleted(jobDetail.Key);
                            }
                        }
                    }
                }
            }

            return found;
        }
Beispiel #19
0
        public async Task <TriggerPropertyBundle> LoadExtendedTriggerProperties(ConnectionAndTransactionHolder conn, TriggerKey triggerKey)
        {
            using (var cmd = DbAccessor.PrepareCommand(conn, AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlSelectCronTriggers, TablePrefix, SchedNameLiteral)))
            {
                DbAccessor.AddCommandParameter(cmd, "triggerName", triggerKey.Name);
                DbAccessor.AddCommandParameter(cmd, "triggerGroup", triggerKey.Group);

                using (var rs = await cmd.ExecuteReaderAsync().ConfigureAwait(false))
                {
                    if (await rs.ReadAsync().ConfigureAwait(false))
                    {
                        string cronExpr   = rs.GetString(AdoConstants.ColumnCronExpression);
                        string timeZoneId = rs.GetString(AdoConstants.ColumnTimeZoneId);

                        CronScheduleBuilder cb = CronScheduleBuilder.CronSchedule(cronExpr);

                        if (timeZoneId != null)
                        {
                            cb.InTimeZone(TimeZoneUtil.FindTimeZoneById(timeZoneId));
                        }

                        return(new TriggerPropertyBundle(cb, null, null));
                    }
                }

                throw new InvalidOperationException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlSelectCronTriggers, TablePrefix, SchedNameLiteral));
            }
        }
 /// <summary>
 /// Determine whether a <see cref="ITrigger" /> with the given identifier already 
 /// exists within the scheduler.
 /// </summary>
 /// <param name="triggerKey">triggerKey the identifier to check for</param>
 /// <returns>true if a Trigger exists with the given identifier</returns>
 public bool CheckExists(TriggerKey triggerKey)
 {
     lock (lockObject)
     {
         return this.Triggers.FindOneByIdAs<BsonDocument>(triggerKey.ToBsonDocument()) != null;
     }
 }
        /// <summary> 
        /// Pause the <see cref="ITrigger" /> with the given name.
        /// </summary>
        public virtual void PauseTrigger(TriggerKey triggerKey)
        {
            lock (lockObject)
            {
                this.Triggers.Update(
                    Query.And(
                        Query.EQ("_id", triggerKey.ToBsonDocument()),
                        Query.EQ("State", "Blocked")),
                    Update.Set("State", "PausedAndBlocked"));

                this.Triggers.Update(
                    Query.And(
                        Query.EQ("_id", triggerKey.ToBsonDocument()),
                        Query.NE("State", "Blocked")),
                    Update.Set("State", "Paused"));
            }
        }
Beispiel #22
0
 /// <summary>
 /// Calls the equivalent method on the 'proxied' <see cref="QuartzScheduler" />.
 /// </summary>
 public virtual ITrigger GetTrigger(TriggerKey triggerKey)
 {
     return(sched.GetTrigger(triggerKey));
 }
        /// <summary>
        /// Resume (un-pause) the <see cref="ITrigger" /> with the given key.
        /// </summary>
        /// <remarks>
        /// If the <see cref="ITrigger" /> missed one or more fire-times, then the
        /// <see cref="ITrigger" />'s misfire instruction will be applied.
        /// </remarks>
        public virtual void ResumeTrigger(TriggerKey triggerKey)
        {
            lock (lockObject)
            {
                IOperableTrigger trigger = this.Triggers.FindOneByIdAs<IOperableTrigger>(triggerKey.ToBsonDocument());

                // does the trigger exist?
                if (trigger == null)
                {
                    return;
                }

                BsonDocument triggerState = this.Triggers.FindOneByIdAs<BsonDocument>(triggerKey.ToBsonDocument());
                // if the trigger is not paused resuming it does not make sense...
                if (triggerState["State"] != "Paused" &&
                    triggerState["State"] != "PausedAndBlocked")
                {
                    return;
                }

                if (this.BlockedJobs.FindOneByIdAs<BsonDocument>(trigger.JobKey.ToBsonDocument()) != null)
                {
                    triggerState["State"] = "Blocked";
                }
                else
                {
                    triggerState["State"] = "Waiting";
                }

                this.ApplyMisfire(trigger);

                this.Triggers.Save(triggerState);
            }
        }
Beispiel #24
0
 /// <summary>
 /// Calls the equivalent method on the 'proxied' <see cref="QuartzScheduler" />.
 /// </summary>
 public virtual DateTimeOffset?RescheduleJob(TriggerKey triggerKey, ITrigger newTrigger)
 {
     return(sched.RescheduleJob(triggerKey, newTrigger));
 }
Beispiel #25
0
 /// <summary>
 /// Calls the equivalent method on the 'proxied' <see cref="QuartzScheduler" />.
 /// </summary>
 public virtual void PauseTrigger(TriggerKey triggerKey)
 {
     sched.PauseTrigger(triggerKey);
 }
Beispiel #26
0
 public void TriggerResumed(TriggerKey triggerKey)
 {
     throw new System.NotImplementedException();
 }
Beispiel #27
0
 public void JobUnscheduled(TriggerKey triggerKey)
 {
     throw new System.NotImplementedException();
 }
Beispiel #28
0
 public async Task DeletScheduleJob(QuartzDTO quartzDTO)
 {
     TriggerKey triggerKey = new TriggerKey(quartzDTO.Id, quartzDTO.Group);
     await _scheduler.UnscheduleJob(triggerKey);
 }
Beispiel #29
0
 /// <summary>
 /// 由于jobkey和triggerkey设置的identity是一样的,获取triggerstate需要triggerkey,因此做一个转变
 /// </summary>
 /// <param name="triggerKey"></param>
 /// <returns></returns>
 public static JobKey ConvertKey(this TriggerKey triggerKey)
 {
     return(new JobKey(triggerKey.Name, triggerKey.Group));
 }
        protected override void PerformOperation(TriggerInput input)
        {
            var triggerKey = new TriggerKey(input.Trigger, input.Group);

            Scheduler.PauseTrigger(triggerKey);
        }
Beispiel #31
0
 /// <summary>
 /// 创建一个触发器(仅执行一次)
 /// </summary>
 /// <param name="key">名称和分组</param>
 /// <param name="startTime">开始时间</param>
 /// <returns></returns>
 public static ITrigger CreateTrigger(TriggerKey key, DateTime startTime)
 {
     return(TriggerBuilder.Create().WithIdentity(key).StartAt(startTime).Build());
 }
Beispiel #32
0
        /// <summary>
        /// Notifies the scheduler listeners about job that was unscheduled.
        /// </summary>
        public virtual void NotifySchedulerListenersUnscheduled(TriggerKey triggerKey)
        {
            // build a list of all scheduler listeners that are to be notified...
            IList<ISchedulerListener> schedListeners = BuildSchedulerListenerList();

            // notify all scheduler listeners
            foreach (ISchedulerListener sl in schedListeners)
            {
                try
                {
                    if (triggerKey == null)
                    {
                        sl.SchedulingDataCleared();
                    }
                    else
                    {
                        sl.JobUnscheduled(triggerKey);
                    }
                }
                catch (Exception e)
                {
                    log.ErrorFormat(
                        CultureInfo.InvariantCulture,
                        "Error while notifying SchedulerListener of unscheduled job. Trigger={0}",
                        e,
                        (triggerKey == null ? "ALL DATA" : triggerKey.ToString()));
                }
            }
        }
 /// <summary>
 /// Retrieve the given <see cref="ITrigger" />.
 /// </summary>
 /// <returns>
 /// The desired <see cref="ITrigger" />, or null if there is no match.
 /// </returns>
 public virtual IOperableTrigger RetrieveTrigger(TriggerKey triggerKey)
 {
     lock (lockObject)
     {
         return this.Triggers
             .FindOneByIdAs<Spi.IOperableTrigger>(triggerKey.ToBsonDocument());
     }
 }
Beispiel #34
0
        /// <summary>
        /// Resume (un-pause) the <see cref="ITrigger" /> with the given
        /// name.
        /// <para>
        /// If the <see cref="ITrigger" /> missed one or more fire-times, then the
        /// <see cref="ITrigger" />'s misfire instruction will be applied.
        /// </para>
        /// </summary>
        public virtual void ResumeTrigger(TriggerKey triggerKey)
        {
            ValidateState();

            resources.JobStore.ResumeTrigger(triggerKey);
            NotifySchedulerThread(null);
            NotifySchedulerListenersResumedTrigger(triggerKey);
        }
        /// <summary>
        /// Get the current state of the identified <see cref="ITrigger" />.
        /// </summary>
        /// <seealso cref="TriggerState.Normal" />
        /// <seealso cref="TriggerState.Paused" />
        /// <seealso cref="TriggerState.Complete" />
        /// <seealso cref="TriggerState.Error" />
        /// <seealso cref="TriggerState.Blocked" />
        /// <seealso cref="TriggerState.None"/>
        public virtual TriggerState GetTriggerState(TriggerKey triggerKey)
        {
            lock (lockObject)
            {
                BsonDocument triggerState = this.Triggers.FindOneByIdAs<BsonDocument>(triggerKey.ToBsonDocument());

                if (triggerState.IsBsonNull)
                {
                    return TriggerState.None;
                }
                if (triggerState["State"] == "Complete")
                {
                    return TriggerState.Complete;
                }
                if (triggerState["State"] == "Paused")
                {
                    return TriggerState.Paused;
                }
                if (triggerState["State"] == "PausedAndBlocked")
                {
                    return TriggerState.Paused;
                }
                if (triggerState["State"] == "Blocked")
                {
                    return TriggerState.Blocked;
                }
                if (triggerState["State"] == "Error")
                {
                    return TriggerState.Error;
                }

                return TriggerState.Normal;
            }
        }
Beispiel #36
0
 private bool MatchTriggerListener(ITriggerListener listener, TriggerKey key)
 {
     IList<IMatcher<TriggerKey>> matchers = ListenerManager.GetTriggerListenerMatchers(listener.Name);
     if (matchers == null)
     {
         return true;
     }
     return matchers.Any(matcher => matcher.IsMatch(key));
 }
 /// <summary>
 /// Remove (delete) the <see cref="ITrigger" /> with the
 /// given name.
 /// </summary>
 /// <returns>
 /// 	<see langword="true" /> if a <see cref="ITrigger" /> with the given
 /// name and group was found and removed from the store.
 /// </returns>
 public virtual bool RemoveTrigger(TriggerKey triggerKey)
 {
     return RemoveTrigger(triggerKey, true);
 }
Beispiel #38
0
        /// <summary>
        /// Get the <see cref="ITrigger" /> instance with the given name and
        /// group.
        /// </summary>
        public virtual ITrigger GetTrigger(TriggerKey triggerKey)
        {
            ValidateState();

            return resources.JobStore.RetrieveTrigger(triggerKey);
        }
Beispiel #39
0
 /// <summary>
 /// Calls the equivalent method on the 'proxied' <see cref="QuartzScheduler" />.
 /// </summary>
 public virtual bool UnscheduleJob(TriggerKey triggerKey)
 {
     return(sched.UnscheduleJob(triggerKey));
 }
Beispiel #40
0
        public async Task <int> DeleteExtendedTriggerProperties(ConnectionAndTransactionHolder conn, TriggerKey triggerKey)
        {
            using (var cmd = DbAccessor.PrepareCommand(conn, AdoJobStoreUtil.ReplaceTablePrefix(StdAdoConstants.SqlDeleteCronTrigger, TablePrefix, SchedNameLiteral)))
            {
                DbAccessor.AddCommandParameter(cmd, "triggerName", triggerKey.Name);
                DbAccessor.AddCommandParameter(cmd, "triggerGroup", triggerKey.Group);

                return(await cmd.ExecuteNonQueryAsync().ConfigureAwait(false));
            }
        }
Beispiel #41
0
 /// <summary>
 /// Calls the equivalent method on the 'proxied' <see cref="QuartzScheduler" />.
 /// </summary>
 public bool CheckExists(TriggerKey triggerKey)
 {
     return(sched.CheckExists(triggerKey));
 }
Beispiel #42
0
 public Task TriggerResumed(TriggerKey triggerKey, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #43
0
 /// <summary>
 /// Calls the equivalent method on the 'proxied' <see cref="QuartzScheduler" />.
 /// </summary>
 public virtual void ResumeTrigger(TriggerKey triggerKey)
 {
     sched.ResumeTrigger(triggerKey);
 }
Beispiel #44
0
 public Task JobUnscheduled(TriggerKey triggerKey, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #45
0
 /// <summary>
 /// Calls the equivalent method on the 'proxied' <see cref="QuartzScheduler" />.
 /// </summary>
 public virtual TriggerState GetTriggerState(TriggerKey triggerKey)
 {
     return(sched.GetTriggerState(triggerKey));
 }
 /// <summary>
 /// Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.IJobDetail" />
 /// is unscheduled.
 /// </summary>
 /// <seealso cref="M:Quartz.ISchedulerListener.SchedulingDataCleared(System.Threading.CancellationToken)" />
 public Task JobUnscheduled(TriggerKey triggerKey, CancellationToken cancellationToken = new CancellationToken())
 {
     return(Task.FromResult(0));
 }
Beispiel #47
0
        /// <summary>
        /// Notifies the scheduler listeners resumed trigger.
        /// </summary>
        public virtual void NotifySchedulerListenersResumedTrigger(TriggerKey triggerKey)
        {
            // build a list of all job listeners that are to be notified...
            IList<ISchedulerListener> schedListeners = BuildSchedulerListenerList();

            // notify all scheduler listeners
            foreach (ISchedulerListener sl in schedListeners)
            {
                try
                {
                    sl.TriggerResumed(triggerKey);
                }
                catch (Exception e)
                {
                    log.Error(string.Format(CultureInfo.InvariantCulture, "Error while notifying SchedulerListener of resumed trigger. Trigger={0}", triggerKey), e);
                }
            }
        }
 /// <summary>
 /// Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.ITrigger" />
 /// has been un-paused.
 /// </summary>
 public Task TriggerResumed(TriggerKey triggerKey, CancellationToken cancellationToken = new CancellationToken())
 {
     return(Task.FromResult(0));
 }
Beispiel #49
0
        /// <summary>
        /// Remove (delete) the <see cref="ITrigger" /> with the
        /// given name, and store the new given one - which must be associated
        /// with the same job.
        /// </summary>
        /// <param name="triggerKey">the key of the trigger</param>
        /// <param name="newTrigger">The new <see cref="ITrigger" /> to be stored.</param>
        /// <returns>
        /// 	<see langword="null" /> if a <see cref="ITrigger" /> with the given
        /// name and group was not found and removed from the store, otherwise
        /// the first fire time of the newly scheduled trigger.
        /// </returns>
        public virtual DateTimeOffset? RescheduleJob(TriggerKey triggerKey, ITrigger newTrigger)
        {
            ValidateState();

            if (triggerKey == null)
            {
                throw new ArgumentException("triggerKey cannot be null");
            }
            if (newTrigger == null)
            {
                throw new ArgumentException("newTrigger cannot be null");
            }

            var trigger = (IOperableTrigger) newTrigger;
            ITrigger oldTrigger = GetTrigger(triggerKey);
            if (oldTrigger == null)
            {
                return null;
            }

            trigger.JobKey = oldTrigger.JobKey;
            trigger.Validate();

            ICalendar cal = null;
            if (newTrigger.CalendarName != null)
            {
                cal = resources.JobStore.RetrieveCalendar(newTrigger.CalendarName);
            }

            DateTimeOffset? ft = trigger.ComputeFirstFireTimeUtc(cal);

            if (!ft.HasValue)
            {
                var message = string.Format("Based on configured schedule, the given trigger '{0}' will never fire.", trigger.Key);
                throw new SchedulerException(message);
            }

            if (resources.JobStore.ReplaceTrigger(triggerKey, trigger))
            {
                NotifySchedulerThread(newTrigger.GetNextFireTimeUtc());
                NotifySchedulerListenersUnscheduled(triggerKey);
                NotifySchedulerListenersScheduled(newTrigger);
            }
            else
            {
                return null;
            }

            return ft;
        }
Beispiel #50
0
 public virtual Task JobUnscheduled(
     TriggerKey triggerKey,
     CancellationToken cancellationToken = default)
 {
     return(TaskUtil.CompletedTask);
 }
Beispiel #51
0
        /// <summary>
        /// Remove the indicated <see cref="ITrigger" /> from the
        /// scheduler.
        /// </summary>
        public virtual bool UnscheduleJob(TriggerKey triggerKey)
        {
            ValidateState();

            if (resources.JobStore.RemoveTrigger(triggerKey))
            {
                NotifySchedulerThread(null);
                NotifySchedulerListenersUnscheduled(triggerKey);
            }
            else
            {
                return false;
            }

            return true;
        }
Beispiel #52
0
 public virtual Task TriggerResumed(
     TriggerKey triggerKey,
     CancellationToken cancellationToken = default)
 {
     return(TaskUtil.CompletedTask);
 }
Beispiel #53
0
        /// <summary>
        /// Determine whether a <see cref="ITrigger" /> with the given identifier already
        /// exists within the scheduler.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="triggerKey">the identifier to check for</param>
        /// <returns>true if a Trigger exists with the given identifier</returns>
        public bool CheckExists(TriggerKey triggerKey)
        {
            ValidateState();

            return resources.JobStore.CheckExists(triggerKey);
        }
Beispiel #54
0
        static public TriggerState getTriggerStatus(string TriggerName, string TriggerGroup)
        {
            TriggerKey objTrigerKey = new TriggerKey(TriggerName, TriggerGroup);

            return(_scheduler.GetTriggerState(objTrigerKey));
        }
Beispiel #55
0
        /// <summary>
        /// Get the current state of the identified <see cref="ITrigger" />.  
        /// </summary>
        /// <seealso cref="TriggerState" />
        public virtual TriggerState GetTriggerState(TriggerKey triggerKey)
        {
            ValidateState();

            return resources.JobStore.GetTriggerState(triggerKey);
        }
 public async Task JobUnscheduled(TriggerKey triggerKey, CancellationToken token = default(CancellationToken))
 {
     await WriteMesssage(".JobUnscheduled", token);
 }
Beispiel #57
0
 /// <summary>
 /// Use a <see cref="TriggerKey" /> with the given name and default group to
 /// identify the Trigger.
 /// </summary>
 /// <remarks>
 /// <para>If none of the 'withIdentity' methods are set on the TriggerBuilder,
 /// then a random, unique TriggerKey will be generated.</para>
 /// </remarks>
 /// <param name="name">the name element for the Trigger's TriggerKey</param>
 /// <returns>the updated TriggerBuilder</returns>
 /// <seealso cref="TriggerKey" />
 /// <seealso cref="ITrigger.Key" />
 public TriggerBuilder WithIdentity(string name)
 {
     key = new TriggerKey(name, null);
     return this;
 }
 public async Task TriggerResumed(TriggerKey triggerKey, CancellationToken token = default(CancellationToken))
 {
     await WriteMesssage(".TriggerResumed", token);
 }
Beispiel #59
0
 /// <summary>
 /// Use the given TriggerKey to identify the Trigger.
 /// </summary>
 /// <remarks>
 /// <para>If none of the 'withIdentity' methods are set on the TriggerBuilder,
 /// then a random, unique TriggerKey will be generated.</para>
 /// </remarks>
 /// <param name="key">the TriggerKey for the Trigger to be built</param>
 /// <returns>the updated TriggerBuilder</returns>
 /// <seealso cref="TriggerKey" />
 /// <seealso cref="ITrigger.Key" />
 public TriggerBuilder WithIdentity(TriggerKey key)
 {
     this.key = key;
     return this;
 }
Beispiel #60
0
 public static ITrigger CreateTrigger(TriggerKey key, string cron)
 {
     return(CreateTrigger(key, cron, DateTime.UtcNow));
 }