public static IScheduler GetSchedulers(IScheduler sched)
        {
            DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 10);

            UnityContainer container = new UnityContainer();

            container.RegisterType <ISiteBLL, SiteBLL>();

            //返回调用者
            ISiteBLL ISite = container.Resolve <SiteBLL>();

            List <JobSite> sites = ISite.getJobSites();

            _logger.InfoFormat("任务初始化共" + sites.Count + "个站点");

            foreach (JobSite s in sites)
            {
                IJobDetail job = JobBuilder.Create <GT.SiteCheck.Job.SiteCheckJob>().WithIdentity(s.site.name, s.node.nodeName).Build();

                ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                         .WithIdentity(s.site.name, s.node.nodeName)
                                         .StartAt(startTime)
                                         .WithSimpleSchedule(x => x.WithIntervalInSeconds(s.site.interval.Value).RepeatForever())                       //.WithRepeatCount(2)
                                         .Build();

                job.JobDataMap.Put(GT.SiteCheck.Job.SiteCheckJob.site, s.site);

                sched.ScheduleJob(job, trigger);
            }

            return(sched);
        }
Exemple #2
0
        public static void Run()
        {
            try
            {
                UnityContainer container = new UnityContainer();
                container.RegisterType <ISiteBLL, SiteBLL>();

                //返回调用者
                ISiteBLL ISite = container.Resolve <SiteBLL>();

                List <JobSite> sites = ISite.getJobSites();

                RemoteScheduler sched = QuartzBase.GetRemoteScheduler();

                ILog log = LogManager.GetLogger(typeof(QuartzScheduler));

                DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 10);

                foreach (JobSite s in sites)
                {
                    IJobDetail job = JobBuilder.Create <SiteCheckJob>().WithIdentity(s.site.name, s.node.nodeName).Build();

                    ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                             .WithIdentity(s.site.name, s.node.nodeName)
                                             .StartAt(startTime)
                                             .WithSimpleSchedule(x => x.WithIntervalInSeconds(s.site.interval.Value).RepeatForever())                       //.WithRepeatCount(2)
                                             .Build();

                    job.JobDataMap.Put(SiteCheckJob.site, s.site);

                    sched.ScheduleJob(job, trigger);
                }

                sched.Start();
            }
            catch (Exception ex)
            {
                _logger.ErrorFormat("JOB启动异常:" + ex.ToString());
            }
        }