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 Flow(RiverContext riverContext) { try { log.Info(string.Format("Configuring river {0}", riverContext.Name)); var reset = new AutoResetEvent(false); var source = Sources.SourceFactory.Get(riverContext.Source); var bed = Beds.BedFactory.Get(riverContext); var mouth = Mouths.MouthFactory.Get(riverContext.Mouth); var flow = from iObj in source.Read() from cObj in bed.Processor(iObj) from jObj in bed.Converter(cObj) select jObj; log.Info(string.Format("Starting river {0}", riverContext.Name)); using (flow.SubscribeOn(Scheduler.Default).Subscribe( drop => { mouth.Collect(drop); }, ex => { log.ErrorFormat("Error while processing river: {0}", ex); throw new ApplicationException("Error while processing river", ex); }, () => { mouth.Expel(); reset.Set(); } )) reset.WaitOne(); log.Info(string.Format("Completed river {0}", riverContext.Name)); } catch (Exception e) { log.Error(string.Format("Error river {0}", riverContext.Name), e); } }
public River(RiverContext riverContext) { _riverContext = riverContext; _source = Sources.Source.GetSource(riverContext.Source); _mouth = new Mouth(riverContext.Destination); }
/* * // POST api/river * public void Post([FromBody]string value) * { * } */ // PUT api/river/5 public void Put(string id, RiverContext riverContext) { WebApiApplication.SchedulerWrapper.ScheduleJob(riverContext); }