private JobDataMap getJobData() { _logger.Info("Preparing Advantic Measure Loader Job Data"); JobDataMap result = new JobDataMap(); result.Put("ConfigurationProvider", _configProvider); result.Put("AdvanticMeasureService", _advanticMeasureService); result.Put("AdvanticSignalService", _advanticSignalService); _logger.Info("Done preparing Advantic Measure Loader Job Data"); return result; }
static void Main(string[] args) { Console.WriteLine("Starting scheduler..."); var properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteServerTestScheduler"; // set thread pool infoD:\Projects\QuartzMaster\QuartzMaster.TestServerHost\Program.cs properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; // set remoting expoter properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz"; properties["quartz.scheduler.exporter.port"] = "500"; properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler"; properties["quartz.scheduler.exporter.channelType"] = "tcp"; var schedulerFactory = new StdSchedulerFactory(properties); scheduler = schedulerFactory.GetScheduler(); // define the job and ask it to run var map = new JobDataMap(); map.Put("msg", "Some message!"); map.Put("msg 2", "Some message 2!"); map.Put("msg 3", "Some message 3!"); var job = new JobDetail("localJob", "default", typeof(NoOpJob)) { JobDataMap = map }; var job2 = new JobDetail("localJob 2", "default", typeof(NoOpJob)) { JobDataMap = map }; var trigger2 = new SimpleTrigger("Simple Trigger", "default", "localJob 2", "default", DateTime.Now, DateTime.Now.AddMinutes(10), SimpleTrigger.RepeatIndefinitely, new TimeSpan(0, 0, 45)); var trigger = new CronTrigger("remotelyAddedTrigger", "default", "localJob", "default", DateTime.UtcNow, null, "/5 * * ? * *"); var trigger3 = new SimpleTrigger("remotelyAddedTriggerB", "default", "localJob", "default", DateTime.Now, DateTime.Now.AddMinutes(10), SimpleTrigger.RepeatIndefinitely, new TimeSpan(0, 0, 45)); // schedule the job scheduler.ScheduleJob(job, trigger3); scheduler.ScheduleJob(job2, trigger2); scheduler.Start(); Console.WriteLine("Scheduler has been started."); Console.WriteLine("Press any key to stop scheduler"); Console.ReadKey(); scheduler.Shutdown(); }
public void ScheduleJob(RiverContext riverContext) { var jobData = new JobDataMap(); jobData.Put("riverContext", riverContext); IJobDetail job = JobBuilder.Create<RiverJob>() .WithIdentity(riverContext.Name) // name "myRiver", group "river" .SetJobData(jobData) .Build(); var triggerBuilder = TriggerBuilder.Create() .WithIdentity(riverContext.Name) .ForJob(riverContext.Name); //, "group1") if(!String.IsNullOrWhiteSpace(riverContext.Cron)) triggerBuilder.WithCronSchedule(riverContext.Cron); else triggerBuilder.StartNow(); var trigger = triggerBuilder.Build(); if (_scheduler.CheckExists(new JobKey(riverContext.Name))) _scheduler.DeleteJob(new JobKey(riverContext.Name)); _scheduler.ScheduleJob(job, trigger); }
public void Start() { Console.WriteLine("Starting scheduler..."); var scheduler = schedulerFactory.GetScheduler(); // define the job and ask it to run var map = new JobDataMap(); map.Put("msg", "Some message!"); var job = JobBuilder.Create<HelloJob>() .WithIdentity("localJob", "default") .UsingJobData(map).RequestRecovery(true).Build(); ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create() .WithIdentity("remotelyAddedTrigger", "default") .WithCronSchedule("/5 * * ? * *") .StartAt(DateTimeOffset.UtcNow) .ForJob(job) .Build(); if (!scheduler.CheckExists(job.Key)) { scheduler.ScheduleJob(job, trigger); } scheduler.Start(); }
private JobDataMap getJobData() { _logger.Info("Preparing Measures EXIM Loader Job Data"); JobDataMap result = new JobDataMap(); result.Put("MeasureService", _service); result.Put("ConfigurationProvider", _configProvider); result.Put("FtpClient", _ftpClient); result.Put("MeasureFileExtracter", _measureFileExtracter); result.Put("PlantPowerService", _plantPowerService); result.Put("PlantPowerFileExtracter", _plantPowerFileExtracter); result.Put("PlantService", _plantService); _logger.Info("Done preparing Measures EXIM Loader Job Data"); return result; }
static void Main(string[] args) { Console.WriteLine("Starting scheduler..."); var properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteServerSchedulerClient"; // set thread pool info properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; // set remoting expoter properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz"; properties["quartz.scheduler.exporter.port"] = "555"; properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler"; properties["quartz.scheduler.exporter.channelType"] = "tcp"; var schedulerFactory = new StdSchedulerFactory(properties); var scheduler = schedulerFactory.GetScheduler(); var map = new JobDataMap(); map.Put("msg", "Some message!"); var job = JobBuilder.Create<PrintMessageJob>() .WithIdentity("localJob", "default") .UsingJobData(map) .Build(); var trigger = TriggerBuilder.Create() .WithIdentity("remotelyAddedTrigger", "default") .ForJob(job) .StartNow() .WithCronSchedule("/5 * * ? * *") .Build(); // schedule the job scheduler.ScheduleJob(job, trigger); scheduler.Start(); Console.WriteLine("Scheduler has been started."); }
public void ScheduleJob() { IJobDetail iJob = JobBuilder.Create<HelloWorld>() .WithIdentity("myJob", "group1") .Build(); JobDataMap map = new JobDataMap(); map.Put("msg", "Your remotely added job has executed!"); ITrigger tgr = TriggerBuilder.Create() .WithIdentity("myTrigger", "group1") .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(10) .WithRepeatCount(3)) .Build(); //Add to Scheduler Scheduler.ScheduleJob(iJob, tgr); }
static void Main(string[] args) { Console.WriteLine("Starting scheduler..."); var properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteServerSchedulerClient"; // set thread pool info properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; // set remoting expoter properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz"; properties["quartz.scheduler.exporter.port"] = "555"; properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler"; properties["quartz.scheduler.exporter.channelType"] = "tcp"; var schedulerFactory = new StdSchedulerFactory(properties); var scheduler = schedulerFactory.GetScheduler(); // define the job and ask it to run var map = new JobDataMap(); map.Put("msg", "Some message!"); var job = new JobDetail("localJob", "default", typeof(NoOpJob)) { JobDataMap = map }; var trigger = new CronTrigger("remotelyAddedTrigger", "default", "localJob", "default", DateTime.UtcNow, null, "/5 * * ? * *"); // schedule the job scheduler.ScheduleJob(job, trigger); scheduler.Start(); Console.WriteLine("Scheduler has been started."); }
public override void Schedule(IScheduler scheduler) { // construct jobs var map = new JobDataMap(); map.Put("msg", "Some message!"); IJobDetail startAchPayments = JobBuilder.Create<StartAchPaymentProcessingJob>() .WithIdentity("StartACHPayments", "Processing") .WithDescription("Starts processing of ACH payments") .StoreDurably(true) .UsingJobData(map) .Build(); var schedule = SchedulingExtensions.DailyAt(4); ITrigger achPaymentsTrigger = TriggerBuilder.Create() .WithIdentity("StartAchPaymentsTriggerDaily", "DailyTriggers") .WithCronSchedule(schedule, c => c.InTimeZone(TimeZoneInfo.Local)) .Build(); scheduler.Clear(); scheduler.ScheduleJob(startAchPayments, achPaymentsTrigger); }
public void Add() { if (this.JobType == null) { MessageBox.Show("请选择任务类型"); return; } if (!this.ReplaceExists) { if (this.Scheduler.CheckExists(new TriggerKey(this.TriggerName, this.TriggerGroup))) { MessageBox.Show("指定的触发器已经存在,请重新指定名称"); return; } if (this.Scheduler.CheckExists(new JobKey(this.JobName, this.JobGroup))) { MessageBox.Show("指定的任务已经存在,请重新指定名称"); return; } } try { var jobBuilder = JobBuilder.Create(this.JobType) .WithIdentity(this.JobName, this.JobGroup) .WithDescription(this.JobDesc); var scheduleBuilder = this.ScheduleBuildByVM.GetScheduleBuilder(); var triggerBuilder = TriggerBuilder.Create() .WithSchedule(scheduleBuilder) .WithIdentity(this.TriggerName, this.TriggerGroup) .WithPriority(this.TriggerPriority) .WithDescription(this.TriggerDesc); var datamap = new JobDataMap(); foreach (var p in this.Parameters) { datamap.Put(p.Key, p.Value); } if (datamap.Count > 0) jobBuilder.UsingJobData(datamap); if (!string.IsNullOrWhiteSpace(this.ChoicedCalendar)) triggerBuilder.ModifiedByCalendar(this.ChoicedCalendar); // 如果是用 AdoStore , 修改一个已经存在的 Trigger 的 ScheduleBuilder 到不同的类型,任务会报错, // 这里如果是不同的类型,先删除 var storType = this.Scheduler.GetMetaData().JobStoreType; if (storType.Equals(typeof(JobStoreTX)) && this.OrgScheduleBuilderType != null && !this.OrgScheduleBuilderType.Equals(scheduleBuilder.GetType()) ) { var key = new JobKey(this.JobName, this.JobGroup); this.Scheduler.DeleteJob(key); } if (this.ReplaceExists) { var triggers = new Quartz.Collection.HashSet<ITrigger>(); triggers.Add(triggerBuilder.Build()); this.Scheduler.ScheduleJob(jobBuilder.Build(), triggers, true); } else { var jd = jobBuilder.Build(); var t = triggerBuilder.Build(); this.Scheduler.ScheduleJob(jd, t); //this.Scheduler.ScheduleJob(jobBuilder.Build(), triggerBuilder.Build()); } MessageBox.Show("保存成功"); } catch (Exception ex) { MessageBox.Show(ex.GetBaseException().Message); } }
/// <summary> /// Add the given key-value pair to the JobDetail's <see cref="JobDataMap" />. /// </summary> ///<returns>the updated JobBuilder</returns> /// <seealso cref="IJobDetail.JobDataMap" /> public JobBuilder UsingJobData(string key, string value) { jobDataMap.Put(key, value); return(this); }
/// <summary> /// Add the given key-value pair to the Trigger's <see cref="JobDataMap" />. /// </summary> /// <remarks> /// </remarks> /// <returns>the updated TriggerBuilder</returns> /// <seealso cref="ITrigger.JobDataMap" /> public TriggerBuilder UsingJobData(JobDataMap newJobDataMap) { // add data from new map to existing map (overrides old values) foreach (string dataKey in jobDataMap.Keys) { newJobDataMap.Put(dataKey, jobDataMap.Get(dataKey)); } jobDataMap = newJobDataMap; // set new map as the map to use return this; }
/// <summary> /// 新增Quartz WebService调度任务 /// </summary> /// <param name="scheduler"></param> /// <param name="esbWS"></param> private void AddQuartzWebServiceScheduler(ESB_SCHD scheduler, ESB_SCHD_EsbWS esbWS) { // define the job and ask it to run JobDetailImpl job = new JobDetailImpl(scheduler.JOB_NAME, scheduler.TRIG_GROUP, typeof(EsbWebServiceJob)); job.Description = scheduler.SCHD_DESC; job.Durable = true; JobDataMap map = new JobDataMap(); map.Put(EsbWebServiceJob.HOST, scheduler.HOST_NAME); map.Put(EsbWebServiceJob.SERVICE_NAME, esbWS.ServiceName); map.Put(EsbWebServiceJob.METHOD_NAME, esbWS.MethodName); map.Put(EsbWebServiceJob.PASSWORD, esbWS.PassWord); map.Put(EsbWebServiceJob.SCHD_ID, scheduler.SCHD_ID); map.Put(EsbWebServiceJob.PARAM_STRING, esbWS.ParamString); map.Put(EsbWebServiceJob.PARAM_URL, esbWS.ParamUrl); job.JobDataMap = map; DateTime startTime = DateTime.Parse(scheduler.START_TIME).ToUniversalTime(); DateTime endTime = DateTime.Parse(scheduler.END_TIME).ToUniversalTime(); CronTriggerImpl trigger = new CronTriggerImpl(scheduler.TRIG_NAME, scheduler.TRIG_GROUP, scheduler.JOB_NAME, scheduler.TRIG_GROUP, startTime, endTime, scheduler.SCHD_CRON); trigger.Description = scheduler.SCHD_DESC; try { sched.ScheduleJob(job, trigger); } catch (Exception ex) { throw ex; } }
Action<IMemberInfo> MapItsValue(JobDataMap jobDataMap, object currentObject) { return info => jobDataMap.Put(info.Name, info.GetValue(currentObject)); }
private static JobDataMap SetJobDataMapFromContext(Job context) { if (context.Message != null && !string.IsNullOrWhiteSpace(context.Message.ToString()) && context.Message.ToString().Trim().StartsWith("{")) { context.Message = JsonConvert.SerializeObject(context.Message); } var jobData = new JobDataMap(); jobData.Put("JobContext", context); return jobData; }
/// <summary> /// Add the given key-value pair to the Trigger's <see cref="JobDataMap" />. /// </summary> /// <remarks> /// </remarks> /// <returns>the updated TriggerBuilder</returns> /// <seealso cref="ITrigger.JobDataMap" /> public TriggerBuilder UsingJobData(JobDataMap newJobDataMap) { // add any existing data to this new map foreach (string k in jobDataMap.Keys) { newJobDataMap.Put(k, jobDataMap.Get(k)); } jobDataMap = newJobDataMap; // set new map as the map to use return this; }
private void StartTask(IEnumerable<TaskModel> list) { foreach (var item in list) { if (item.Status != (int)Status.WaitRun) continue; var ass = Assembly.LoadFile(item.Dll); var type = ass.GetTypes().FirstOrDefault(x => x.FullName.EndsWith(item.Type)); type = _baseJobType.MakeGenericType(type); var data = new JobDataMap(); data.Put("taskObject", item); var jobDetail = JobBuilder.Create(type).UsingJobData(data) .WithIdentity(item.Name) .Build(); ITrigger trigger; if (item.RunType == (int)RunType.Interval) { //隔多少秒执行 trigger = TriggerBuilder.Create() .WithIdentity(item.Name) .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(item.Interval) .RepeatForever()) .Build(); } else { //指定时间执行 trigger = TriggerBuilder.Create() .WithIdentity(item.Name) .StartNow() .WithSchedule( CronScheduleBuilder.DailyAtHourAndMinute(item.Hour, item.Minute) ) .Build(); } scheduler.ScheduleJob(jobDetail, trigger); item.Status = (int)Status.Runing; } }