private JobDataMap BuildDailyJobDataMap() { JobDataMap JobDataMap = new JobDataMap(); JobDataMap.Add("DailySample", (bool)chkWIPSample.EditValue); JobDataMap.Add("DailyQC", (bool)chkWIPQC.EditValue); JobDataMap.Add("DailySubcon", (bool)chkWIPSubcon.EditValue); return JobDataMap; }
static void Main(string[] args) { log4net.GlobalContext.Properties["LogName"] = "TriggerFishDemo"; log4net.Config.XmlConfigurator.Configure(); Container.Install(new TriggerFishDemoServiceContainerInstaller()); var jobData = new JobDataMap(); jobData.Add("JobName", "Aquarium.TriggerFish"); jobData.Add("JobDescription", "TriggerFish Demo - run a job on a customized schedule"); TriggerFishSetupFactory.SetupService<FeedingTimeJob>(jobData, new FeedingTimeTriggers()); }
public void AddRepeatingJob(Type aType, string aName, string aGroup, int aSecondsToSleep, params JobItem[] aItems) { JobKey key = new JobKey(aName, aGroup); if (Scheduler.GetJobDetail(key) != null) { Log.Error("AddRepeatingJob(" + aType.Name + ", " + aName + ", " + aGroup + ") already exists"); return; } Log.Info("AddRepeatingJob(" + aType.Name + ", " + aName + ", " + aGroup + ", " + aSecondsToSleep + ")"); _scheduledJobs.Add(key); var data = new JobDataMap(); foreach (JobItem item in aItems) { data.Add(item.Key, item.Value); } IJobDetail job = JobBuilder.Create(aType) .WithIdentity(key) .UsingJobData(data) .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity(aName, aGroup) .WithSimpleSchedule(x => x.WithIntervalInSeconds(aSecondsToSleep).RepeatForever()) .Build(); Scheduler.ScheduleJob(job, trigger); }
/// <summary> /// Builds a Quartz Job for a specified <see cref="Rock.Model.ServiceJob">Job</see> /// </summary> /// <param name="job">The <see cref="Rock.Model.ServiceJob"/> to create a Quarts Job for.</param> /// <returns>A object that implements the <see cref="Quartz.IJobDetail"/> interface</returns> public IJobDetail BuildQuartzJob( ServiceJob job ) { // build the type object, will depend if the class is in an assembly or the App_Code folder Type type = null; if ( job.Assembly == string.Empty || job.Assembly == null ) { type = BuildManager.GetType( job.Class, false ); } else { string thetype = string.Format( "{0}, {1}", job.Class, job.Assembly ); type = Type.GetType( thetype ); } // load up job attributes (parameters) job.LoadAttributes(); JobDataMap map = new JobDataMap(); foreach ( KeyValuePair<string, List<Rock.Model.AttributeValue>> attrib in job.AttributeValues ) { map.Add( attrib.Key, attrib.Value[0].Value ); } // create the quartz job object IJobDetail jobDetail = JobBuilder.Create( type ) .WithDescription( job.Id.ToString() ) .WithIdentity( new Guid().ToString(), job.Name ) .UsingJobData( map ) .Build(); return jobDetail; }
public static void Start(HttpMonitor monitor) { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); var jobDataMap = new JobDataMap(); jobDataMap.Add("monitor", monitor); IJobDetail job = JobBuilder.Create<ReportJob>().SetJobData(jobDataMap).Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity(monitor.Name, monitor.Group) .WithSimpleSchedule(t => t.WithIntervalInSeconds(monitor.MonitoringFrequency) .RepeatForever()) .Build(); scheduler.ScheduleJob(job, trigger); LogHelper.PureLog(string.Format("{0}:已开启【{1}】\r\n", DateTime.Now, monitor.Name), string.Format("StartMonitorLog_{0}.txt", DateTime.Now.ToString("yyyyMMdd"))); }
/// <summary> /// Builds a Quartz Job for a specified <see cref="Rock.Model.ServiceJob">Job</see> /// </summary> /// <param name="job">The <see cref="Rock.Model.ServiceJob"/> to create a Quarts Job for.</param> /// <returns>A object that implements the <see cref="Quartz.IJobDetail"/> interface</returns> public IJobDetail BuildQuartzJob( ServiceJob job ) { // build the type object, will depend if the class is in an assembly or the App_Code folder Type type = null; if ( string.IsNullOrWhiteSpace(job.Assembly) ) { // first try to load the job type from the App_Code folder type = BuildManager.GetType( job.Class, false ); if (type == null) { // if it couldn't be loaded from the app_code folder, look in Rock.dll string thetype = string.Format( "{0}, {1}", job.Class, this.GetType().Assembly.FullName ); type = Type.GetType( thetype ); } } else { // if an assembly is specified, load the type from that string thetype = string.Format( "{0}, {1}", job.Class, job.Assembly ); type = Type.GetType( thetype ); } // load up job attributes (parameters) job.LoadAttributes(); JobDataMap map = new JobDataMap(); foreach ( var attrib in job.AttributeValues ) { map.Add( attrib.Key, attrib.Value.Value ); } // create the quartz job object IJobDetail jobDetail = JobBuilder.Create( type ) .WithDescription( job.Id.ToString() ) .WithIdentity( job.Guid.ToString(), job.Name ) .UsingJobData( map ) .Build(); return jobDetail; }
/// <summary> /// Builds the quartz job. /// </summary> /// <param name="job">The job.</param> /// <returns></returns> public IJobDetail BuildQuartzJob(Job job) { // build the type object, will depend if the class is in an assembly or the App_Code folder Type type = null; if ( job.Assemby == string.Empty || job.Assemby == null ) { type = BuildManager.GetType( job.Class, false ); } else { string thetype = string.Format( "{0}, {1}", job.Class, job.Assemby ); type = Type.GetType( thetype ); } // create attributes if needed // TODO: next line should be moved to Job creation UI, when it's created Rock.Attribute.Helper.UpdateAttributes( type, "Rock.Util.Job", "Class", job.Class, null ); // load up job attributes (parameters) Rock.Attribute.Helper.LoadAttributes( job ); JobDataMap map = new JobDataMap(); foreach ( KeyValuePair<string, KeyValuePair<string, string>> attrib in job.AttributeValues ) { map.Add( attrib.Key, attrib.Value.Value ); } // create the quartz job object IJobDetail jobDetail = JobBuilder.Create( type ) .WithDescription( job.Id.ToString() ) .WithIdentity( new Guid().ToString(), job.Name ) .UsingJobData(map) .Build(); return jobDetail; }
private JobDataMap getJobDataMap() { JobDataMap map = new JobDataMap(); foreach (ListViewItem item in jobDataListView.Items) { map.Add(item.SubItems[0].Text, item.SubItems[1].Text); } return map; }
private IJobDetail CreateJobDetail() { var jobData = new JobDataMap(); jobData.Add("JobItem", this); var builder = JobBuilder.Create<JobRunner>(); builder.WithIdentity(this.ID.ToString()) .WithDescription(this.Data.Name) .UsingJobData(jobData); return builder.Build(); }
private static JobDataMap GetJobDataMap(ISchJob job) { var res = new JobDataMap(); foreach (var p in job.Job_JobParam_List) res.Add(p.Name, p.Value); return res; }
/// <summary> /// Schedule specified trigger /// </summary> /// <param name="myTrigger"></param> public Guid ScheduleTrigger(BaseTrigger myTrigger) { Guid triggerId = Guid.Empty; // Set default values DateTimeOffset startAt = (DateTime.MinValue != myTrigger.StartDateTime) ? myTrigger.StartDateTime : DateTime.Now; // Set default trigger group myTrigger.Group = (!string.IsNullOrEmpty(myTrigger.Group)) ? myTrigger.Group : TriggerKey.DefaultGroup; // Check if jobDetail already exists var jobKey = new JobKey(myTrigger.JobName, myTrigger.JobGroup); // If jobDetail does not exist, throw if (!_scheduler.CheckExists(jobKey)) { throw new Exception(string.Format("Job does not exist. Name = {0}, Group = {1}", myTrigger.CalendarName, myTrigger.JobGroup)); } IJobDetail jobDetail = _scheduler.GetJobDetail(jobKey); var jobDataMap = new JobDataMap(); if (myTrigger.JobDataMap != null && myTrigger.JobDataMap.Count > 0) { foreach (var jobData in myTrigger.JobDataMap) { jobDataMap.Add(jobData.Key, jobData.Value); } } var cronTrigger = myTrigger as CronTrigger; if (cronTrigger != null) { //SmartPolicy Action<CronScheduleBuilder> misFireAction = x => {}; switch (cronTrigger.MisfireInstruction) { case MisfireInstructionCron.DoNothing: misFireAction = builder => builder.WithMisfireHandlingInstructionDoNothing(); break; case MisfireInstructionCron.FireOnceNow: misFireAction = builder => builder.WithMisfireHandlingInstructionFireAndProceed(); break; case MisfireInstructionCron.Ignore: misFireAction = builder => builder.WithMisfireHandlingInstructionIgnoreMisfires(); break; } var trigger = (ICronTrigger)TriggerBuilder.Create() .WithIdentity(myTrigger.Name, myTrigger.Group) .ForJob(jobDetail) .UsingJobData(jobDataMap) .ModifiedByCalendar(!string.IsNullOrEmpty(cronTrigger.CalendarName) ? cronTrigger.CalendarName : null) .WithCronSchedule(cronTrigger.CronExpression, misFireAction) .StartAt(startAt) .Build(); trigger.TimeZone = TimeZoneInfo.Local; using (var tran = new TransactionScope()) { triggerId = _persistanceStore.UpsertTriggerKeyIdMap(myTrigger.Name, myTrigger.Group); _scheduler.ScheduleJob(trigger); tran.Complete(); } } var simpleTrigger = myTrigger as SimpleTrigger; if (simpleTrigger != null) { //SmartPolicy Action<SimpleScheduleBuilder> misFireAction = x => x.WithInterval(simpleTrigger.RepeatInterval) .WithRepeatCount(simpleTrigger.RepeatCount); switch (simpleTrigger.MisfireInstruction) { case MisfireInstructionSimple.FireNow: misFireAction = builder => builder.WithInterval(simpleTrigger.RepeatInterval) .WithRepeatCount(simpleTrigger.RepeatCount).WithMisfireHandlingInstructionFireNow(); break; case MisfireInstructionSimple.Ignore: misFireAction = builder => builder.WithInterval(simpleTrigger.RepeatInterval) .WithRepeatCount(simpleTrigger.RepeatCount).WithMisfireHandlingInstructionIgnoreMisfires(); break; case MisfireInstructionSimple.RescheduleNextWithExistingCount: misFireAction = builder => builder.WithInterval(simpleTrigger.RepeatInterval) .WithRepeatCount(simpleTrigger.RepeatCount).WithMisfireHandlingInstructionNextWithExistingCount(); break; case MisfireInstructionSimple.RescheduleNextWithRemainingCount: misFireAction = builder => builder.WithInterval(simpleTrigger.RepeatInterval) .WithRepeatCount(simpleTrigger.RepeatCount).WithMisfireHandlingInstructionNextWithRemainingCount(); break; case MisfireInstructionSimple.RescheduleNowWithExistingRepeatCount: misFireAction = builder => builder.WithInterval(simpleTrigger.RepeatInterval) .WithRepeatCount(simpleTrigger.RepeatCount).WithMisfireHandlingInstructionNowWithExistingCount(); break; case MisfireInstructionSimple.RescheduleNowWithRemainingRepeatCount: misFireAction = builder => builder.WithInterval(simpleTrigger.RepeatInterval) .WithRepeatCount(simpleTrigger.RepeatCount).WithMisfireHandlingInstructionNowWithRemainingCount(); break; } var trigger = (ISimpleTrigger)TriggerBuilder.Create() .WithIdentity(myTrigger.Name, myTrigger.Group) .ForJob(jobDetail) .UsingJobData(jobDataMap) .ModifiedByCalendar(!string.IsNullOrEmpty(simpleTrigger.CalendarName) ? simpleTrigger.CalendarName : null) .StartAt(startAt) .WithSimpleSchedule(misFireAction) .Build(); using (var tran = new TransactionScope()) { triggerId = _persistanceStore.UpsertTriggerKeyIdMap(myTrigger.Name, myTrigger.Group); _scheduler.ScheduleJob(trigger); tran.Complete(); } } return triggerId; }
public void ScheduleJobs() { try { //start a scheduler var schedulerMetaData = scheduler.GetMetaData(); Log.Info("Scheduler Metadata Summary =>", this); Log.Info(schedulerMetaData.GetSummary(), this); Log.Info("SchedulerInstanceId : " + schedulerMetaData.SchedulerInstanceId, this); Log.Info("SchedulerName : " + schedulerMetaData.SchedulerName, this); Log.Info("ThreadPoolSize : " + schedulerMetaData.ThreadPoolSize, this); Log.Info("ThreadPoolType: " + schedulerMetaData.ThreadPoolType.ToString(), this); Log.Info("JobStoreType: " + schedulerMetaData.JobStoreType.ToString(), this); scheduler.Start(); //Create Job Definitions and add it to the collection to simulate this is what we will get from Sitecore Log.Info("Getting Job Definitions", this); var jobDefinitions = GetConfiguredJobs(); //Cleanup any existing jobs scheduled already //to ensure that every time ScheduleJobs is called, //it schedules the whole list of jobs from fresh Log.Info("Clearing existing scheduled Jobs before we set it up agin !", this); scheduler.Clear(); if (jobDefinitions != null && jobDefinitions.Count > 0) { foreach (JobDetail jd in jobDefinitions) { //if (jd.JobKey.Equals("Cleanup Publish Queue")) //{ JobDataMap jobDataMap = new JobDataMap(); //Get Job Data Map NameValueCollection jobDataCollection = Sitecore.Web.WebUtil.ParseUrlParameters(jd.JobData); foreach (string key in jobDataCollection.Keys) { jobDataMap.Add(key, jobDataCollection[key]); } // define the job and tie it to our HelloJob class var job = JobBuilder.Create(Type.GetType(jd.Type, true, true)) .WithIdentity(jd.JobKey, jd.Group) .WithDescription(jd.Description) .UsingJobData(jobDataMap) .Build(); Log.Info(String.Format("Job {0} created", jd.JobKey), this); Log.Info(String.Format("Getting triggers for job {0}", jd.JobKey), this); var triggersForJob = GetTriggersForJob(jd); Quartz.Collection.HashSet<ITrigger> triggers = new Quartz.Collection.HashSet<ITrigger>(); ITriggerListener trigListener = new SchedulerTriggerListener(); #region "Looping through trigger Details" foreach (TriggerDetail td in triggersForJob) { TriggerBuilder trigger = GetTriggerBuilder(jd, td); //Add Job and Trigger listeners Log.Info("Registering Trigger Listener", this); scheduler.ListenerManager.AddTriggerListener(trigListener, EverythingMatcher<JobKey>.AllTriggers()); triggers.Add(trigger.Build()); Log.Info(String.Format("Job {0} is being scheduled with trigger {1}.", jd.JobKey, td.TriggerKey), this); } #endregion try { scheduler.ScheduleJob(job, triggers, true); } catch (JobExecutionException jobExeEX) { Log.Error(String.Format("Sitecore.QuartzScheuler: Error Occured in {0}", jobExeEX.Source) + jobExeEX.Message + Environment.NewLine + jobExeEX.StackTrace, this); } catch (SchedulerException schedulerEx) { Log.Error(String.Format("Sitecore.QuartzScheuler: Error Occured in {0}", schedulerEx.Source) + schedulerEx.Message + Environment.NewLine + schedulerEx.StackTrace, this); } catch (Exception ex) { Log.Error(String.Format("Sitecore.QuartzScheuler: Error occured while schedule job {0}", jd.JobKey), this); Log.Error("Sitecore.QuartzScheuler: " + ex.Message + Environment.NewLine + ex.StackTrace, this); } } } else { Log.Info("No Jobs found. No jobs will be scheduled.", this); } //} } catch (Exception ex) { Log.Error("Sitecore.QuartzScheuler: " + ex.Message + Environment.NewLine + ex.StackTrace, this); } }
public IJobDetail CreateAndAddJob(Type aType, string aName, string aGroup, params JobItem[] aItems) { var key = new JobKey(aName, aGroup); if (Scheduler.GetJobDetail(key) != null) { Log.Error("CreateAndAddJob(" + aType.Name + ", " + aName + ", " + aGroup + ") already exists"); return null; } Log.Info("CreateAndAddJob(" + aType.Name + ", " + aName + ", " + aGroup + ")"); _scheduledJobs.Add(key); var data = new JobDataMap(); foreach (JobItem item in aItems) { data.Add(item.Key, item.Value); } IJobDetail job = JobBuilder.Create(aType) .WithIdentity(key) .UsingJobData(data) .Build(); return job; }