internal virtual bool SubmitJobException(SchedulingItem job, Exception exception) { var handler = SchedulingItemExceptionHandler; if (handler != null) { handler(job, exception); return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> /// <exception cref="ArgumentNullException">If one of the parameters is /// is a null reference.</exception> /// <exception cref="InvalidOperationException">If the configuration does not allow /// proper scheduling, e.g. because several loops were specified, but the inverval is /// missing.</exception> public SchedulingItemContext(SchedulingItem managedJob, Action <SchedulingItem> callbackAction) { if (managedJob == null) { throw new ArgumentNullException("managedJob"); } if (callbackAction == null) { throw new ArgumentNullException("callbackAction"); } //make sure we have an interval if we have more than one loop TimeSpan?interval = managedJob.Interval; if (interval == null) { if (managedJob.Loops == null || managedJob.Loops.Value > 1) { string msg = "Job [{0}] is invalid: Specifiy either a single run, or a loop interval."; msg = String.Format(msg, managedJob.Id); throw new InvalidOperationException(msg); } } ManagedJob = managedJob; CallbackAction = callbackAction; NextExecution = managedJob.StartTime; //adjust starting time if the initial time was in the past, //but rather start immediately var now = SchedulingTimeHelpers.Now(); if (NextExecution.Value < now) { NextExecution = now; } RemainingExecutions = managedJob.Loops; }
public virtual void Submit(SchedulingItem schedulingItem, Action <SchedulingItem> callback) { if (schedulingItem == null) { throw new ArgumentNullException("schedulingItem"); } if (callback == null) { throw new ArgumentNullException("callback"); } var interval = schedulingItem.Interval; if (interval.HasValue && interval.Value.TotalMilliseconds < MinJobInterval) { string msg = "Interval of {0} ms is too small - a minimum interval of {1} ms is accepted."; msg = String.Format(msg, interval.Value.TotalMilliseconds, MinJobInterval); throw new InvalidOperationException(msg); } var context = new SchedulingItemContext(schedulingItem, callback); lock (SyncRoot) { if (NextExecution == null || context.NextExecution <= NextExecution.Value) { SchedulingItems.Insert(0, context); if (NextExecution == null || NextExecution.Value.Subtract(SchedulingTimeHelpers.Now()).TotalMilliseconds > MinJobInterval) { Reschedule(); } } else { SchedulingItems.Add(context); IsSorted = false; } } }
public SchedulingApi(SchedulingItem schedulingItem) { _schedulingItem = schedulingItem; }