Ejemplo n.º 1
0
 public void TriggerComplete(Trigger trigger, JobExecutionContext context, SchedulerInstruction triggerInstructionCode)
 {
     if (!trigger.Name.Equals("TimerTrigger"))
     {
         Account account = (Account)trigger.JobDataMap.Get("account");
         if (account != null)
         {
             SimpleTrigger triggerObject = new SimpleTrigger(account.Login + "Trigger", "account", DateTime.MinValue, null, 0, TimeSpan.Zero);
             triggerObject.JobName = account.Login + "Job";
             triggerObject.StartTimeUtc = DateTime.UtcNow.AddSeconds(new Random().Next(account.Settings.NextTimeLoginMin, account.Settings.NextTimeLoginMax));
             account.SchedulerTrigger = triggerObject;
             triggerObject.JobDataMap.Add("account", account);
             m_accountManager.SetNextLoginTimeForAccount(account);
         }
     }
 }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        try
        {
            SchedulableRpt rpt = SchedulableRpt.GetSchedulableRptByRptName(this.ReportType);

            int existTriggerCount = rpt.GetTriggerCount(this.UserID, this.SelectedFrequency);

            int            maxTriggerCount;
            Quartz.Trigger trigger = this.GetTrigger(out maxTriggerCount);

            if (existTriggerCount >= maxTriggerCount)
            {
                this.ShowMessage(existTriggerCount + " " + this.SelectedFrequency + " schedule setted. No more allowed.");
            }
            else
            {
                rpt.AddToScheduler(
                    trigger,
                    this.UserID,
                    this.SelectedFrequency,
                    this.Parameters,
                    this.Availability,
                    this.PastType,
                    this.PastUnit,
                    this.ckbMonitor.Checked,
                    this.CheckTriggerID);
                this.RadGrid2.Rebind();
                this.ShowMessage("Report schedule trigger set successful");
            }
        }
        catch (Exception ex)
        {
            this.ShowMessage("Add trigger error! \r\n => " + ex.Message);
        }
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Add the given trigger to the Scheduler, if it doesn't already exist.
 /// Overwrites the trigger in any case if "overwriteExistingJobs" is set.
 /// </summary>
 /// <param name="trigger">the trigger to add</param>
 /// <returns><code>true</code> if the trigger was actually added, <code>false</code> if it already existed before</returns>
 private bool AddTriggerToScheduler(Trigger trigger)
 {
     bool triggerExists = (GetScheduler().GetTrigger(trigger.Name, trigger.Group) != null);
     if (!triggerExists || this.overwriteExistingJobs)
     {
         // Check if the Trigger is aware of an associated JobDetail.
         if (trigger is IJobDetailAwareTrigger)
         {
             JobDetail jobDetail = ((IJobDetailAwareTrigger) trigger).JobDetail;
             // Automatically register the JobDetail too.
             if (!jobDetails.Contains(jobDetail) && AddJobToScheduler(jobDetail))
             {
                 jobDetails.Add(jobDetail);
             }
         }
         if (!triggerExists)
         {
             try
             {
                 GetScheduler().ScheduleJob(trigger);
             }
             catch (ObjectAlreadyExistsException ex)
             {
                 if (logger.IsDebugEnabled)
                 {
                     logger.Debug(
                         "Unexpectedly found existing trigger, assumably due to cluster race condition: " +
                         ex.Message + " - can safely be ignored");
                 }
                 if (overwriteExistingJobs)
                 {
                     GetScheduler().RescheduleJob(trigger.Name, trigger.Group, trigger);
                 }
             }
         }
         else
         {
             GetScheduler().RescheduleJob(trigger.Name, trigger.Group, trigger);
         }
         return true;
     }
     else
     {
         return false;
     }
 }
 public TimeTriggerCommandArgs(string jobName, Trigger timeTrigger, Action action)
 {
     this.ActionName = jobName;
     this.TimeTrigger = timeTrigger;
     this.Action = action;
 }
		/// <summary>
		/// Returns a list of Dates that are the next fire times of a
		/// <see cref="Trigger" />.
		/// The input trigger will be cloned before any work is done, so you need
		/// not worry about its state being altered by this method.
		/// </summary>
		/// <param name="trigg">The trigger upon which to do the work</param>
		/// <param name="cal">The calendar to apply to the trigger's schedule</param>
		/// <param name="numTimes">The number of next fire times to produce</param>
		/// <returns>List of java.util.Date objects</returns>
		public static IList ComputeFireTimes(Trigger trigg, ICalendar cal, int numTimes)
		{
			ArrayList lst = new ArrayList();

			Trigger t = (Trigger) trigg.Clone();

			if (t.GetNextFireTimeUtc() == null || !t.GetNextFireTimeUtc().HasValue)
			{
				t.ComputeFirstFireTimeUtc(cal);
			}

			for (int i = 0; i < numTimes; i++)
			{
                NullableDateTime d = t.GetNextFireTimeUtc();
                if (d.HasValue)
				{
					lst.Add(d);
					t.Triggered(cal);
				}
				else
				{
					break;
				}
			}

			return ArrayList.ReadOnly(new ArrayList(lst));
		}
		/// <summary>
		/// Set the given <see cref="Trigger" />'s name to the given value, and its
		/// group to the default group (<see cref="SchedulerConstants.DefaultGroup" />).
		/// </summary>
		/// <param name="trig">the tigger to change name to</param>
		/// <param name="name">the new trigger name</param>
		public static void SetTriggerIdentity(Trigger trig, string name)
		{
			SetTriggerIdentity(trig, name, SchedulerConstants.DefaultGroup);
		}
        /// <summary>
        /// Schedule the given <see cref="Trigger" /> with the
        /// <see cref="IJob" /> identified by the <see cref="Trigger" />'s settings.
        /// </summary>
        public virtual DateTime ScheduleJob(SchedulingContext ctxt, Trigger trigger)
        {
            ValidateState();

            if (trigger == null)
            {
                throw new SchedulerException("Trigger cannot be null",
                        SchedulerException.ErrorClientError);
            }

            trigger.Validate();

            ICalendar cal = null;
            if (trigger.CalendarName != null)
            {
                cal = resources.JobStore.RetrieveCalendar(ctxt, trigger.CalendarName);
                if (cal == null)
                {
                    throw new SchedulerException(string.Format(CultureInfo.InvariantCulture, "Calendar not found: {0}", trigger.CalendarName),
                                                 SchedulerException.ErrorPersistenceCalendarDoesNotExist);
                }
            }

            NullableDateTime ft = trigger.ComputeFirstFireTimeUtc(cal);

            if (!ft.HasValue)
            {
                throw new SchedulerException("Based on configured schedule, the given trigger will never fire.",
                                             SchedulerException.ErrorClientError);
            }

            resources.JobStore.StoreTrigger(ctxt, trigger, false);
            NotifySchedulerThread(trigger.GetNextFireTimeUtc());
            NotifySchedulerListenersScheduled(trigger);

            return ft.Value;
        }
        /// <summary>
        /// Notifies the scheduler listeners about finalized trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public virtual void NotifySchedulerListenersFinalized(Trigger trigger)
        {
            // build a list of all scheduler listeners that are to be notified...
            IList schedListeners = SchedulerListeners;

            // notify all scheduler listeners
            foreach (ISchedulerListener sl in schedListeners)
            {
                try
                {
                    sl.TriggerFinalized(trigger);
                }
                catch (Exception e)
                {
                    Log.Error(string.Format(CultureInfo.InvariantCulture, "Error while notifying SchedulerListener of finalized trigger.  Triger={0}", trigger.FullName), e);
                }
            }
        }
 /// <summary>
 /// Notifies the job store job complete.
 /// </summary>
 /// <param name="ctxt">The job scheduling context.</param>
 /// <param name="trigger">The trigger.</param>
 /// <param name="detail">The detail.</param>
 /// <param name="instCode">The instruction code.</param>
 protected internal virtual void NotifyJobStoreJobComplete(SchedulingContext ctxt, Trigger trigger, JobDetail detail,
                                                           SchedulerInstruction instCode)
 {
     resources.JobStore.TriggeredJobComplete(ctxt, trigger, detail, instCode);
 }
 protected virtual void ReleaseAcquiredTrigger(ConnectionAndTransactionHolder conn,
                                                        SchedulingContext ctxt, Trigger trigger)
 {
     try
     {
         Delegate.UpdateTriggerStateFromOtherState(conn, trigger.Name, trigger.Group, StateWaiting,
                                                   StateAcquired);
         Delegate.DeleteFiredTrigger(conn, trigger.FireInstanceId);
     }
     catch (Exception e)
     {
         throw new JobPersistenceException("Couldn't release acquired trigger: " + e.Message, e);
     }
 }
 /// <summary>
 /// Inform the <see cref="IJobStore" /> that the scheduler no longer plans to
 /// fire the given <see cref="Trigger" />, that it had previously acquired
 /// (reserved).
 /// </summary>
 public void ReleaseAcquiredTrigger(SchedulingContext ctxt, Trigger trigger)
 {
     ExecuteInNonManagedTXLock(LockTriggerAccess, new ReleaseAcquiredTriggerCallback(this, ctxt, trigger));
 }
        protected virtual bool ReplaceTrigger(ConnectionAndTransactionHolder conn, SchedulingContext ctxt,
                                                       string triggerName,
                                                       string groupName, Trigger newTrigger)
        {
            try
            {
                // this must be called before we delete the trigger, obviously
                JobDetail job = Delegate.SelectJobForTrigger(conn, triggerName, groupName, TypeLoadHelper);

                if (job == null)
                {
                    return false;
                }

                if (!newTrigger.JobName.Equals(job.Name) || !newTrigger.JobGroup.Equals(job.Group))
                {
                    throw new JobPersistenceException("New trigger is not related to the same job as the old trigger.");
                }

                bool removedTrigger = DeleteTriggerAndChildren(conn, triggerName, groupName);

                StoreTrigger(conn, ctxt, newTrigger, job, false, StateWaiting, false, false);

                return removedTrigger;
            }
            catch (Exception e)
            {
                throw new JobPersistenceException("Couldn't remove trigger: " + e.Message, e);
            }
        }
 public ReplaceTriggerCallback(JobStoreSupport js, SchedulingContext ctxt, string triggerName,
                               string groupName, Trigger newTrigger)
     : base(js)
 {
     this.ctxt = ctxt;
     this.triggerName = triggerName;
     this.groupName = groupName;
     this.newTrigger = newTrigger;
 }
 /// <see cref="IJobStore.ReplaceTrigger(SchedulingContext, string, string, Trigger)" />
 public bool ReplaceTrigger(SchedulingContext ctxt, string triggerName, string groupName, Trigger newTrigger)
 {
     return
         (bool)
         ExecuteInLock(LockTriggerAccess,
                       new ReplaceTriggerCallback(this, ctxt, triggerName, groupName, newTrigger));
 }
        /// <summary>
        /// Insert or update a trigger.
        /// </summary>
        protected virtual void StoreTrigger(ConnectionAndTransactionHolder conn, SchedulingContext ctxt,
                                                     Trigger newTrigger,
                                                     JobDetail job, bool replaceExisting, string state, bool forceState,
                                                     bool recovering)
        {
            if (newTrigger.Volatile && Clustered)
            {
                Log.Info("note: volatile triggers are effectively non-volatile in a clustered environment.");
            }

            bool existingTrigger = TriggerExists(conn, newTrigger.Name, newTrigger.Group);


            if ((existingTrigger) && (!replaceExisting))
            {
                throw new ObjectAlreadyExistsException(newTrigger);
            }

            try
            {
                if (!forceState)
                {
                    bool shouldBepaused = Delegate.IsTriggerGroupPaused(conn, newTrigger.Group);

                    if (!shouldBepaused)
                    {
                        shouldBepaused = Delegate.IsTriggerGroupPaused(conn, AllGroupsPaused);

                        if (shouldBepaused)
                        {
                            Delegate.InsertPausedTriggerGroup(conn, newTrigger.Group);
                        }
                    }

                    if (shouldBepaused &&
                        (state.Equals(StateWaiting) || state.Equals(StateAcquired)))
                    {
                        state = StatePaused;
                    }
                }

                if (job == null)
                {
                    job = Delegate.SelectJobDetail(conn, newTrigger.JobName, newTrigger.JobGroup, TypeLoadHelper);
                }
                if (job == null)
                {
                    throw new JobPersistenceException("The job (" + newTrigger.FullJobName +
                                                      ") referenced by the trigger does not exist.");
                }
                if (job.Volatile && !newTrigger.Volatile)
                {
                    throw new JobPersistenceException("It does not make sense to " +
                                                      "associate a non-volatile Trigger with a volatile Job!");
                }

                if (job.Stateful && !recovering)
                {
                    state = CheckBlockedState(conn, ctxt, job.Name, job.Group, state);
                }
                if (existingTrigger)
                {
                    if (newTrigger is SimpleTrigger && !newTrigger.HasAdditionalProperties)
                    {
                        Delegate.UpdateSimpleTrigger(conn, (SimpleTrigger)newTrigger);
                    }
                    else if (newTrigger is CronTrigger && !newTrigger.HasAdditionalProperties)
                    {
                        Delegate.UpdateCronTrigger(conn, (CronTrigger)newTrigger);
                    }
                    else
                    {
                        Delegate.UpdateBlobTrigger(conn, newTrigger);
                    }
                    Delegate.UpdateTrigger(conn, newTrigger, state, job);
                }
                else
                {
                    Delegate.InsertTrigger(conn, newTrigger, state, job);
                    if (newTrigger is SimpleTrigger && !newTrigger.HasAdditionalProperties)
                    {
                        Delegate.InsertSimpleTrigger(conn, (SimpleTrigger)newTrigger);
                    }
                    else if (newTrigger is CronTrigger && !newTrigger.HasAdditionalProperties)
                    {
                        Delegate.InsertCronTrigger(conn, (CronTrigger)newTrigger);
                    }
                    else
                    {
                        Delegate.InsertBlobTrigger(conn, newTrigger);
                    }
                }
            }
            catch (Exception e)
            {
                string message = String.Format("Couldn't store trigger '{0}' for '{1}' job: {2}", newTrigger.Name, newTrigger.JobName, e.Message);
                throw new JobPersistenceException(message, e);
            }
        }
 public StoreJobAndTriggerCallback(JobStoreSupport js, JobDetail newJob, Trigger newTrigger,
                                   SchedulingContext ctxt)
     : base(js)
 {
     this.newJob = newJob;
     this.newTrigger = newTrigger;
     this.ctxt = ctxt;
 }
 public virtual TriggerFiredBundle TriggerFired(SchedulingContext ctxt, Trigger trigger)
 {
     return
         (TriggerFiredBundle)
         ExecuteInNonManagedTXLock(LockTriggerAccess, new TriggerFiredCallback(this, ctxt, trigger));
 }
        /// <summary>
        /// Notifies the trigger listeners about misfired trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public virtual void NotifyTriggerListenersMisfired(Trigger trigger)
        {
            // build a list of all trigger listeners that are to be notified...
            IList listeners = BuildTriggerListenerList(trigger.TriggerListenerNames);

            // notify all trigger listeners in the list
            foreach (ITriggerListener tl in listeners)
            {
                try
                {
                    tl.TriggerMisfired(trigger);
                }
                catch (Exception e)
                {
                    SchedulerException se = new SchedulerException(string.Format(CultureInfo.InvariantCulture, "TriggerListener '{0}' threw exception: {1}", tl.Name, e.Message), e);
                    se.ErrorCode = SchedulerException.ErrorTriggerListener;
                    throw se;
                }
            }
        }
 public TriggerFiredCallback(JobStoreSupport js, SchedulingContext ctxt, Trigger trigger)
     : base(js)
 {
     this.ctxt = ctxt;
     this.trigger = trigger;
 }
        /// <summary> 
        /// Add the <see cref="IJob" /> identified by the given
        /// <see cref="JobDetail" /> to the Scheduler, and
        /// associate the given <see cref="Trigger" /> with it.
        /// <p>
        /// If the given Trigger does not reference any <see cref="IJob" />, then it
        /// will be set to reference the Job passed with it into this method.
        /// </p>
        /// </summary>
        public virtual DateTime ScheduleJob(SchedulingContext ctxt, JobDetail jobDetail, Trigger trigger)
        {
            ValidateState();


            if (jobDetail == null)
            {
                throw new SchedulerException("JobDetail cannot be null",
                        SchedulerException.ErrorClientError);
            }

            if (trigger == null)
            {
                throw new SchedulerException("Trigger cannot be null",
                        SchedulerException.ErrorClientError);
            }

            jobDetail.Validate();

            if (trigger.JobName == null)
            {
                trigger.JobName = jobDetail.Name;
                trigger.JobGroup = jobDetail.Group;
            }
            else if (trigger.JobName != null && !trigger.JobName.Equals(jobDetail.Name))
            {
                throw new SchedulerException("Trigger does not reference given job!", SchedulerException.ErrorClientError);
            }
            else if (trigger.JobGroup != null && !trigger.JobGroup.Equals(jobDetail.Group))
            {
                throw new SchedulerException("Trigger does not reference given job!", SchedulerException.ErrorClientError);
            }

            trigger.Validate();

            ICalendar cal = null;
            if (trigger.CalendarName != null)
            {
                cal = resources.JobStore.RetrieveCalendar(ctxt, trigger.CalendarName);
                if (cal == null)
                {
                    throw new SchedulerException(string.Format(CultureInfo.InvariantCulture, "Calendar not found: {0}", trigger.CalendarName),
                                                 SchedulerException.ErrorPersistenceCalendarDoesNotExist);
                }
            }

            NullableDateTime ft = trigger.ComputeFirstFireTimeUtc(cal);

            if (!ft.HasValue)
            {
                throw new SchedulerException("Based on configured schedule, the given trigger will never fire.",
                                             SchedulerException.ErrorClientError);
            }

            resources.JobStore.StoreJobAndTrigger(ctxt, jobDetail, trigger);
            NotifySchedulerThread(trigger.GetNextFireTimeUtc());
            NotifySchedulerListenersScheduled(trigger);

            return ft.Value;
        }
        protected virtual TriggerFiredBundle TriggerFired(ConnectionAndTransactionHolder conn,
                                                                   SchedulingContext ctxt,
                                                                   Trigger trigger)
        {
            JobDetail job;
            ICalendar cal = null;

            // Make sure trigger wasn't deleted, paused, or completed...
            try
            {
                // if trigger was deleted, state will be StateDeleted
                String state = Delegate.SelectTriggerState(conn, trigger.Name, trigger.Group);
                if (!state.Equals(StateAcquired))
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                throw new JobPersistenceException("Couldn't select trigger state: " + e.Message, e);
            }

            try
            {
                job = RetrieveJob(conn, ctxt, trigger.JobName, trigger.JobGroup);
                if (job == null)
                {
                    return null;
                }
            }
            catch (JobPersistenceException jpe)
            {
                try
                {
                    Log.Error("Error retrieving job, setting trigger state to ERROR.", jpe);
                    Delegate.UpdateTriggerState(conn, trigger.Name, trigger.Group, StateError);
                }
                catch (Exception sqle)
                {
                    Log.Error("Unable to set trigger state to ERROR.", sqle);
                }
                throw;
            }

            if (trigger.CalendarName != null)
            {
                cal = RetrieveCalendar(conn, ctxt, trigger.CalendarName);
                if (cal == null)
                {
                    return null;
                }
            }

            try
            {
                Delegate.DeleteFiredTrigger(conn, trigger.FireInstanceId);
                Delegate.InsertFiredTrigger(conn, trigger, StateExecuting, job);
            }
            catch (Exception e)
            {
                throw new JobPersistenceException("Couldn't insert fired trigger: " + e.Message, e);
            }

            NullableDateTime prevFireTime = trigger.GetPreviousFireTimeUtc();

            // call triggered - to update the trigger's next-fire-time state...
            trigger.Triggered(cal);

            String state2 = StateWaiting;
            bool force = true;

            if (job.Stateful)
            {
                state2 = StateBlocked;
                force = false;
                try
                {
                    Delegate.UpdateTriggerStatesForJobFromOtherState(conn, job.Name, job.Group, StateBlocked,
                                                                     StateWaiting);
                    Delegate.UpdateTriggerStatesForJobFromOtherState(conn, job.Name, job.Group, StateBlocked,
                                                                     StateAcquired);
                    Delegate.UpdateTriggerStatesForJobFromOtherState(conn, job.Name, job.Group, StatePausedBlocked,
                                                                     StatePaused);
                }
                catch (Exception e)
                {
                    throw new JobPersistenceException("Couldn't update states of blocked triggers: " + e.Message, e);
                }
            }

            if (!trigger.GetNextFireTimeUtc().HasValue)
            {
                state2 = StateComplete;
                force = true;
            }

            StoreTrigger(conn, ctxt, trigger, job, true, state2, force, false);

            job.JobDataMap.ClearDirtyFlag();

            return new TriggerFiredBundle(
                job, 
                trigger, 
                cal, 
                trigger.Group.Equals(SchedulerConstants.DefaultRecoveryGroup),
                DateTime.UtcNow,
                trigger.GetPreviousFireTimeUtc(), 
                prevFireTime, 
                trigger.GetNextFireTimeUtc());
        }
        /// <summary>
        /// Remove (delete) the <see cref="Trigger" /> with the
        /// given name, and store the new given one - which must be associated
        /// with the same job.
        /// </summary>
        /// <param name="ctxt">The scheduling context.</param>
        /// <param name="triggerName">The name of the <see cref="Trigger" /> to be removed.</param>
        /// <param name="groupName">The group name of the <see cref="Trigger" /> to be removed.</param>
        /// <param name="newTrigger">The new <see cref="Trigger" /> to be stored.</param>
        /// <returns>
        /// 	<see langword="null" /> if a <see cref="Trigger" /> 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 NullableDateTime RescheduleJob(SchedulingContext ctxt, string triggerName, string groupName, Trigger newTrigger)
        {
            ValidateState();

            if (groupName == null)
            {
                groupName = SchedulerConstants.DefaultGroup;
            }

            newTrigger.Validate();

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

            NullableDateTime ft = newTrigger.ComputeFirstFireTimeUtc(cal);

            if (!ft.HasValue)
            {
                throw new SchedulerException("Based on configured schedule, the given trigger will never fire.",
                                             SchedulerException.ErrorClientError);
            }

            if (resources.JobStore.ReplaceTrigger(ctxt, triggerName, groupName, newTrigger))
            {
                NotifySchedulerThread(newTrigger.GetNextFireTimeUtc());
                NotifySchedulerListenersUnscheduled(triggerName, groupName);
                NotifySchedulerListenersScheduled(newTrigger);
            }
            else
            {
                return null;
            }

            return ft;
        }
 /// <summary>
 /// Inform the <see cref="IJobStore" /> that the scheduler has completed the
 /// firing of the given <see cref="Trigger" /> (and the execution its
 /// associated <see cref="IJob" />), and that the <see cref="JobDataMap" />
 /// in the given <see cref="JobDetail" /> should be updated if the <see cref="IJob" />
 /// is stateful.
 /// </summary>
 public virtual void TriggeredJobComplete(SchedulingContext ctxt, Trigger trigger, JobDetail jobDetail,
                                          SchedulerInstruction triggerInstCode)
 {
     ExecuteInNonManagedTXLock(LockTriggerAccess,
                               new TriggeredJobCompleteCallback(this, ctxt, trigger, triggerInstCode, jobDetail));
 }
		/// <summary>
		/// Set the given <see cref="Trigger" />'s name to the given value, and its
		/// group to the given group.
		/// </summary>
		/// <param name="trig">the tigger to change name to</param>
		/// <param name="name">the new trigger name</param>
		/// <param name="group">the new trigger group</param>
		public static void SetTriggerIdentity(Trigger trig, string name, string group)
		{
			trig.Name = name;
			trig.Group = group;
		}
 public TriggeredJobCompleteCallback(JobStoreSupport js, SchedulingContext ctxt, Trigger trigger,
                                     SchedulerInstruction triggerInstCode, JobDetail jobDetail)
     : base(js)
 {
     this.ctxt = ctxt;
     this.trigger = trigger;
     this.triggerInstCode = triggerInstCode;
     this.jobDetail = jobDetail;
 }
		/// <summary>
		/// Returns a list of Dates that are the next fire times of a  <see cref="Trigger" />
		/// that fall within the given date range. The input trigger will be cloned
		/// before any work is done, so you need not worry about its state being
		/// altered by this method.
		/// <p>
		/// NOTE: if this is a trigger that has previously fired within the given
		/// date range, then firings which have already occured will not be listed
		/// in the output List.
		/// </p>
		/// </summary>
		/// <param name="trigg">The trigger upon which to do the work</param>
		/// <param name="cal">The calendar to apply to the trigger's schedule</param>
		/// <param name="from">The starting date at which to find fire times</param>
		/// <param name="to">The ending date at which to stop finding fire times</param>
		/// <returns>List of java.util.Date objects</returns>
		public static IList ComputeFireTimesBetween(Trigger trigg, ICalendar cal, DateTime from, DateTime to)
		{
			ArrayList lst = new ArrayList();

			Trigger t = (Trigger) trigg.Clone();

			if (t.GetNextFireTimeUtc() == null || !t.GetNextFireTimeUtc().HasValue)
			{
				t.StartTimeUtc = from;
				t.EndTimeUtc = to;
				t.ComputeFirstFireTimeUtc(cal);
			}

			// TODO: this method could be more efficient by using logic specific
			//        to the type of trigger ...
			while (true)
			{
                NullableDateTime d = t.GetNextFireTimeUtc();
                if (d.HasValue)
				{
					if (d.Value < from)
					{
						t.Triggered(cal);
						continue;
					}
					if (d.Value > to)
					{
						break;
					}
					lst.Add(d);
					t.Triggered(cal);
				}
				else
				{
					break;
				}
			}
			return ArrayList.ReadOnly(new ArrayList(lst));
		}
        protected virtual void TriggeredJobComplete(ConnectionAndTransactionHolder conn, SchedulingContext ctxt,
                                                             Trigger trigger,
                                                             JobDetail jobDetail, SchedulerInstruction triggerInstCode)
        {
            try
            {
                if (triggerInstCode == SchedulerInstruction.DeleteTrigger)
                {
                    if (!trigger.GetNextFireTimeUtc().HasValue)
                    {
                        // double check for possible reschedule within job 
                        // execution, which would cancel the need to delete...
                        TriggerStatus stat = Delegate.SelectTriggerStatus(conn, trigger.Name, trigger.Group);
                        if (stat != null && !stat.NextFireTimeUtc.HasValue)
                        {
                            RemoveTrigger(conn, ctxt, trigger.Name, trigger.Group);
                        }
                    }
                    else
                    {
                        RemoveTrigger(conn, ctxt, trigger.Name, trigger.Group);
                        signaler.SignalSchedulingChange(null);
                    }
                }
                else if (triggerInstCode == SchedulerInstruction.SetTriggerComplete)
                {
                    Delegate.UpdateTriggerState(conn, trigger.Name, trigger.Group, StateComplete);
                    signaler.SignalSchedulingChange(null);
                }
                else if (triggerInstCode == SchedulerInstruction.SetTriggerError)
                {
                    Log.Info("Trigger " + trigger.FullName + " set to ERROR state.");
                    Delegate.UpdateTriggerState(conn, trigger.Name, trigger.Group, StateError);
                    signaler.SignalSchedulingChange(null);
                }
                else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersComplete)
                {
                    Delegate.UpdateTriggerStatesForJob(conn, trigger.JobName, trigger.JobGroup, StateComplete);
                    signaler.SignalSchedulingChange(null);
                }
                else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersError)
                {
                    Log.Info("All triggers of Job " + trigger.FullJobName + " set to ERROR state.");
                    Delegate.UpdateTriggerStatesForJob(conn, trigger.JobName, trigger.JobGroup, StateError);
                    signaler.SignalSchedulingChange(null);
                }

                if (jobDetail.Stateful)
                {
                    Delegate.UpdateTriggerStatesForJobFromOtherState(conn, jobDetail.Name, jobDetail.Group,
                                                                     StateWaiting, StateBlocked);

                    Delegate.UpdateTriggerStatesForJobFromOtherState(conn, jobDetail.Name, jobDetail.Group,
                                                                     StatePaused,
                                                                     StatePausedBlocked);
                    signaler.SignalSchedulingChange(null);

                    try
                    {
                        if (jobDetail.JobDataMap.Dirty)
                        {
                            Delegate.UpdateJobData(conn, jobDetail);
                        }
                    }
                    catch (IOException e)
                    {
                        throw new JobPersistenceException("Couldn't serialize job data: " + e.Message, e);
                    }
                    catch (Exception e)
                    {
                        throw new JobPersistenceException("Couldn't update job data: " + e.Message, e);
                    }
                }
            }
            catch (Exception e)
            {
                throw new JobPersistenceException("Couldn't update trigger state(s): " + e.Message, e);
            }

            try
            {
                Delegate.DeleteFiredTrigger(conn, trigger.FireInstanceId);
            }
            catch (Exception e)
            {
                throw new JobPersistenceException("Couldn't delete fired trigger: " + e.Message, e);
            }
        }
        /// <summary>
        /// Create a JobExcecutionContext with the given context data.
        /// </summary>
        public JobExecutionContext(IScheduler scheduler, TriggerFiredBundle firedBundle, IJob job)
        {
            this.scheduler = scheduler;
            trigger = firedBundle.Trigger;
            calendar = firedBundle.Calendar;
            jobDetail = firedBundle.JobDetail;
            this.job = job;
            recovering = firedBundle.Recovering;
            fireTimeUtc = firedBundle.FireTimeUtc;
            scheduledFireTimeUtc = firedBundle.ScheduledFireTimeUtc;
            prevFireTimeUtc = firedBundle.PrevFireTimeUtc;
            nextFireTimeUtc = firedBundle.NextFireTimeUtc;

            jobDataMap = new JobDataMap();
            jobDataMap.PutAll(jobDetail.JobDataMap);
            jobDataMap.PutAll(trigger.JobDataMap);
        }
        private void DoUpdateOfMisfiredTrigger(ConnectionAndTransactionHolder conn, SchedulingContext ctxt, Trigger trig,
                                               bool forceState, string newStateIfNotComplete, bool recovering)
        {
            ICalendar cal = null;
            if (trig.CalendarName != null)
            {
                cal = RetrieveCalendar(conn, ctxt, trig.CalendarName);
            }

            signaler.NotifyTriggerListenersMisfired(trig);

            trig.UpdateAfterMisfire(cal);

            if (!trig.GetNextFireTimeUtc().HasValue)
            {
                StoreTrigger(conn, ctxt, trig, null, true, StateComplete, forceState, recovering);
            }
            else
            {
                StoreTrigger(conn, ctxt, trig, null, true, newStateIfNotComplete, forceState, false);
            }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Creates a simple fired bundle
 /// </summary>
 /// <param name="jobType">Type of job.</param>
 /// <param name="trigger">Trigger instance</param>
 /// <returns>Simple TriggerFiredBundle</returns>
 public static TriggerFiredBundle CreateFiredBundleWithTypedJobDetail(Type jobType, Trigger trigger)
 {
     JobDetail jobDetail = new JobDetail("jobName", "jobGroup", jobType);
     TriggerFiredBundle bundle = new TriggerFiredBundle(
         jobDetail, trigger, null, false, null, null, null, null);
     return bundle;
 }
 /// <summary>
 /// Store the given <see cref="JobDetail" /> and <see cref="Trigger" />.
 /// </summary>
 /// <param name="ctxt">SchedulingContext</param>
 /// <param name="newJob">Job to be stored.</param>
 /// <param name="newTrigger">Trigger to be stored.</param>
 public void StoreJobAndTrigger(SchedulingContext ctxt, JobDetail newJob, Trigger newTrigger)
 {
     ExecuteInLock((LockOnInsert) ? LockTriggerAccess : null,
                   new StoreJobAndTriggerCallback(this, newJob, newTrigger, ctxt));
 }