/// <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 JobContext(Job managedJob, Action<Job> 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.JobId); 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 DateTimeOffset now = SystemTime.Now(); if (NextExecution.Value < now) NextExecution = now; RemainingExecutions = managedJob.Loops; }
public static void Register(HttpConfiguration config) { Scheduler = new Scheduler(); TmxGasJob = new Job(); ForexJob = new Job(); MyWeatherJob = new Job(); PlantStatusJob = new Job(); TmxGasJob.Run.From(DateTime.Now).Every.Hours(1); ForexJob.Run.From(DateTime.Now).Every.Hours(1); MyWeatherJob.Run.From(DateTime.Now).Every.Days(1); PlantStatusJob.Run.From(DateTime.Now).Every.Minutes(5); TmxGasJob.Pause(); ForexJob.Pause(); MyWeatherJob.Pause(); PlantStatusJob.Pause(); Scheduler.SubmitJob(TmxGasJob, p => GasIndexDownloader.Process()); Scheduler.SubmitJob(ForexJob, p => ForexDownloader.Process()); Scheduler.SubmitJob(TmxGasJob, p => MyWeatherDownloader.Process()); Scheduler.SubmitJob(PlantStatusJob, p => PlantStatusDownloader.Process()); var context = new TBSPEntities1(); IQueryable<AppSetting> backgroundEnabled = (context.AppSettings.Where( appSetting => appSetting.Description == "BackgroundQueueEnabled") ).Take(1); if (!backgroundEnabled.Any()) throw new Exception("Unable to find background queue config"); if (!backgroundEnabled.First().Value.ToUpper().Equals("TRUE")) { TBSPLogger.Info("SchedulerConfig", "Skipping Background Jobs"); } else { TBSPLogger.Info("SchedulerConfig", "Starting Background Jobs"); TmxGasJob.Resume(); ForexJob.Resume(); MyWeatherJob.Resume(); PlantStatusJob.Resume(); } }
/// <summary> /// Creates the instance object with the job to be /// configured. /// </summary> public JobSchedule(Job job) { this.job = job; }