コード例 #1
0
        public void Schedule(int startDay, int endDay, int periodDays, int jobExecutionCount,
                             TriggerScheduleAction misfireAction,
                             TriggerScheduleCondition condition, int timeBasisDay, bool isFirstTime,
                             TriggerScheduleAction expectedAction, int expectedFireDay,
                             int expectedJobExecutionCountRemaining, bool expectedIsActive, bool expectedIsFirstTime)
        {
            DateTime startTime            = new DateTime(1970, 1, startDay);
            DateTime?endTime              = endDay != 0 ? new DateTime(1970, 1, endDay) : (DateTime?)null;
            TimeSpan?period               = periodDays != 0 ? new TimeSpan(periodDays, 0, 0, 0) : (TimeSpan?)null;
            int?     jobExecutionCountArg = jobExecutionCount >= 0 ? jobExecutionCount : (int?)null;
            DateTime timeBasis            = new DateTime(1970, 1, timeBasisDay);
            DateTime?expectedFireTime     = expectedFireDay != 0
                                                        ? new DateTime(1970, 1, expectedFireDay, 0, 0, 0, DateTimeKind.Utc)
                                                        : (DateTime?)null;
            int?expectedJobExecutionCountRemainingArg = expectedJobExecutionCountRemaining >= 0
                                                                        ? expectedJobExecutionCountRemaining
                                                                        : (int?)null;

            PeriodicTrigger trigger = new PeriodicTrigger(startTime, endTime, period, jobExecutionCountArg);

            trigger.MisfireAction    = misfireAction;
            trigger.MisfireThreshold = TimeSpan.Zero;
            trigger.IsFirstTime      = expectedIsFirstTime;

            TriggerScheduleAction action = trigger.Schedule(condition, timeBasis, null);

            Assert.AreEqual(expectedAction, action);
            DateTimeAssert.AreEqualIncludingKind(expectedFireTime, trigger.NextFireTimeUtc);
            Assert.AreEqual(expectedJobExecutionCountRemainingArg, trigger.JobExecutionCountRemaining);
            Assert.AreEqual(expectedIsActive, trigger.IsActive);
        }
コード例 #2
0
        public void SchedulerTriggeredJob_WithSkipAction(bool misfire,
                                                         bool nextTriggerFireTimeNotNull,
                                                         bool nextTriggerMisfireThresholdNotNull)
        {
            // Create a job scheduled to fire 3 minutes in the past.
            // We cause a misfire by setting a threshold for 2 seconds which clearly is
            // in the past.  Otherwise we set the threshold to 1 minute which clearly is satisfiable.
            DateTime   schedTime  = DateTime.UtcNow.AddSeconds(-3);
            JobDetails jobDetails = new JobDetails(dummyJobSpec, schedTime.AddSeconds(-5));

            jobDetails.JobState = JobState.Triggered;

            if (nextTriggerFireTimeNotNull)
            {
                jobDetails.NextTriggerFireTimeUtc = schedTime;
            }
            if (nextTriggerMisfireThresholdNotNull)
            {
                jobDetails.NextTriggerMisfireThreshold = misfire ? new TimeSpan(0, 0, 2) : new TimeSpan(0, 1, 0);
            }

            PrepareMockJobWatcher(jobDetails);

            TriggerScheduleCondition expectedCondition = misfire
                                                                        ? TriggerScheduleCondition.Misfire
                                                                        : TriggerScheduleCondition.Fire;

            Expect.Call(mockTrigger.Schedule(expectedCondition, DateTime.MinValue, null))
            .Constraints(Rhino.Mocks.Constraints.Is.Equal(expectedCondition), Rhino.Mocks.Constraints.Is.Anything(), Rhino.Mocks.Constraints.Is.Null())
            .Return(TriggerScheduleAction.Skip);
            Expect.Call(mockTrigger.NextFireTimeUtc).Return(new DateTime(1970, 1, 5, 0, 0, 0, DateTimeKind.Utc));
            Expect.Call(mockTrigger.NextMisfireThreshold).Return(new TimeSpan(0, 2, 0));

            mockJobStore.SaveJobDetails(jobDetails);
            LastCall.Do((SaveJobDetailsDelegate)WakeOnSaveJobDetails);

            Mocks.ReplayAll();

            RunSchedulerUntilWake();

            Assert.AreEqual(JobState.Scheduled, jobDetails.JobState);
            DateTimeAssert.AreEqualIncludingKind(new DateTime(1970, 1, 5, 0, 0, 0, DateTimeKind.Utc),
                                                 jobDetails.NextTriggerFireTimeUtc);
            Assert.AreEqual(new TimeSpan(0, 2, 0), jobDetails.NextTriggerMisfireThreshold);
            Assert.IsNull(jobDetails.JobSpec.JobData);
            Assert.IsNull(jobDetails.LastJobExecutionDetails);
        }
コード例 #3
0
        /// <inheritdoc />
        public override TriggerScheduleAction Schedule(TriggerScheduleCondition condition, DateTime timeBasisUtc,
                                                       JobExecutionDetails lastJobExecutionDetails)
        {
            timeBasisUtc = DateTimeUtils.AssumeUniversalTime(timeBasisUtc);

            switch (condition)
            {
            case TriggerScheduleCondition.Latch:
                return(ScheduleSuggestedAction(TriggerScheduleAction.Skip, timeBasisUtc));

            case TriggerScheduleCondition.Misfire:
                isFirstTime = false;
                return(ScheduleSuggestedAction(misfireAction, timeBasisUtc));

            case TriggerScheduleCondition.Fire:
                isFirstTime = false;
                return(ScheduleSuggestedAction(TriggerScheduleAction.ExecuteJob, timeBasisUtc));

            default:
                throw new SchedulerException(String.Format(CultureInfo.CurrentCulture,
                                                           "Unrecognized trigger schedule condition '{0}'.", condition));
            }
        }
コード例 #4
0
 /// <summary>
 /// Updates the trigger's scheduling state machine in response to a condition
 /// and informs the scheduler as to what action should be taken.
 /// </summary>
 /// <remarks>
 /// The implementation should use the value of the <paramref name="timeBasisUtc"/>
 /// parameter to evaluate its scheduling rules rather than calling <see cref="DateTime.UtcNow" />.
 /// </remarks>
 /// <param name="condition">The reason the trigger is being scheduled</param>
 /// <param name="timeBasisUtc">The UTC time to use as a basis for evaluating scheduling rules and
 /// that should be considered as referring to "Now."</param>
 /// <param name="lastJobExecutionDetails">The results of the most recent job execution which may be
 /// used to provide different trigger responses based on whether a job succeeded or failed.
 /// The value is null if the job has never executed.</param>
 /// <returns>The action that the scheduler should perform in response</returns>
 public abstract TriggerScheduleAction Schedule(TriggerScheduleCondition condition, DateTime timeBasisUtc,
                                                JobExecutionDetails lastJobExecutionDetails);
コード例 #5
0
		/// <inheritdoc />
		public override TriggerScheduleAction Schedule(TriggerScheduleCondition condition, DateTime timeBasisUtc,
		                                               JobExecutionDetails lastJobExecutionDetails)
		{
			timeBasisUtc = DateTimeUtils.AssumeUniversalTime(timeBasisUtc);

			switch (condition)
			{
				case TriggerScheduleCondition.Latch:
					return ScheduleSuggestedAction(TriggerScheduleAction.Skip, timeBasisUtc);

				case TriggerScheduleCondition.Misfire:
					isFirstTime = false;
					return ScheduleSuggestedAction(misfireAction, timeBasisUtc);

				case TriggerScheduleCondition.Fire:
					isFirstTime = false;
					return ScheduleSuggestedAction(TriggerScheduleAction.ExecuteJob, timeBasisUtc);

				default:
					throw new SchedulerException(String.Format(CultureInfo.CurrentCulture,
					                                           "Unrecognized trigger schedule condition '{0}'.", condition));
			}
		}
コード例 #6
0
ファイル: PeriodicTriggerTest.cs プロジェクト: QMTech/Attic
        public void Schedule(int startDay, int endDay, int periodDays, int jobExecutionCount,
            TriggerScheduleAction misfireAction,
            TriggerScheduleCondition condition, int timeBasisDay, bool isFirstTime,
            TriggerScheduleAction expectedAction, int expectedFireDay,
            int expectedJobExecutionCountRemaining, bool expectedIsActive, bool expectedIsFirstTime)
        {
            DateTime startTime = new DateTime(1970, 1, startDay);
            DateTime? endTime = endDay != 0 ? new DateTime(1970, 1, endDay) : (DateTime?) null;
            TimeSpan? period = periodDays != 0 ? new TimeSpan(periodDays, 0, 0, 0) : (TimeSpan?) null;
            int? jobExecutionCountArg = jobExecutionCount >= 0 ? jobExecutionCount : (int?) null;
            DateTime timeBasis = new DateTime(1970, 1, timeBasisDay);
            DateTime? expectedFireTime = expectedFireDay != 0
                                         	? new DateTime(1970, 1, expectedFireDay, 0, 0, 0, DateTimeKind.Utc)
                                         	: (DateTime?) null;
            int? expectedJobExecutionCountRemainingArg = expectedJobExecutionCountRemaining >= 0
                                                         	? expectedJobExecutionCountRemaining
                                                         	: (int?) null;

            PeriodicTrigger trigger = new PeriodicTrigger(startTime, endTime, period, jobExecutionCountArg);
            trigger.MisfireAction = misfireAction;
            trigger.MisfireThreshold = TimeSpan.Zero;
            trigger.IsFirstTime = expectedIsFirstTime;

            TriggerScheduleAction action = trigger.Schedule(condition, timeBasis, null);
            Assert.AreEqual(expectedAction, action);
            DateTimeAssert.AreEqualIncludingKind(expectedFireTime, trigger.NextFireTimeUtc);
            Assert.AreEqual(expectedJobExecutionCountRemainingArg, trigger.JobExecutionCountRemaining);
            Assert.AreEqual(expectedIsActive, trigger.IsActive);
        }