Пример #1
0
        private void Init(NameValueCollection props)
        {
            if (props == null)
            {
                props = new NameValueCollection();
            }
            if (String.IsNullOrWhiteSpace(props.Get(StdSchedulerFactory.PropertySchedulerInstanceName)))
            {
                props.Set(StdSchedulerFactory.PropertySchedulerInstanceName, Guid.NewGuid().ToString());
            }

            ActorTaskScheduler.RunTask(async() =>
            {
                if (props == null)
                {
                    Scheduler = await new StdSchedulerFactory().GetScheduler();
                }
                else
                {
                    Scheduler = await new StdSchedulerFactory(props).GetScheduler();
                }

                await Scheduler.Start();
                OnSchedulerCreated(Scheduler);
            });
        }
Пример #2
0
 public void Initialize(string pluginName, Quartz.IScheduler sched)
 {
     logger.Info("SmartNodePlugin 开始初始化");
     mName  = pluginName;
     mSched = sched;
     logger.Info("SmartNodePlugin 初始化结束");
 }
Пример #3
0
    public void ExecuteScheduler()
    {
        try
        {
            StdSchedulerFactory factory   = new StdSchedulerFactory();
            Quartz.IScheduler   scheduler = factory.GetScheduler();


            // and start it off
            scheduler.Start();

            // define the job and tie it to our HelloJob class
            IJobDetail job = JobBuilder.Create <ParseJob>()
                             .WithIdentity("job1", "group1")
                             .Build();

            // Trigger the job to run now, and then repeat every 10 seconds
            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("trigger1", "group1")
                               .StartNow()
                               .WithSimpleSchedule(x => x
                                                   .WithInterval(new TimeSpan(10, 0, 0, 0))
                                                   .RepeatForever())
                               .Build();

            // Tell quartz to schedule the job using our trigger
            scheduler.ScheduleJob(job, trigger);
        }
        catch (SchedulerException se)
        {
            Console.WriteLine(se);
        }
    }
Пример #4
0
 public SchedulingActor(IScheduler scheduler)
 {
     _logger.Debug("Scheduling actor started at path {Path}", Self.Path);
     _scheduler = scheduler;
     Receive <ScheduleCommand>(message => Schedule(message));
     Receive <ScheduleMessage>(message => Schedule(message));
     Receive <Unschedule>(message => Unschedule(message));
 }
Пример #5
0
 public SchedulingActor()
 {
     _publisher = Context.System.GetTransport();
     _logger.Debug("Scheduling actor started at path {Path}", Self.Path);
     _scheduler = Context.System.GetExtension <SchedulingExtension>().Scheduler;
     ReceiveAsync <ScheduleCommandExecution>(Schedule);
     Receive <Unschedule>(message => Unschedule(message));
 }
Пример #6
0
        public ScheduleContainer()
        {
            var ssf = new StdSchedulerFactory();

            Scheduler = ssf.GetScheduler();
            Scheduler.Start();
            Scheduler.Context.Add("Container", this);
        }
Пример #7
0
        public QuartzCronSchedulerViaCommandLine(Options options, IJobFactory jobFactory, ILoggerFactoryAdapter loggerFactory)
        {
            _options              = options;
            _scheduler            = StdSchedulerFactory.GetDefaultScheduler();
            _scheduler.JobFactory = jobFactory;

            LogManager.Adapter = loggerFactory;
            _logger            = LogManager.GetLogger("Quartz.Net");
        }
Пример #8
0
 public SpiderController(PortalDbContext dbContext,
                         PortalOptions options,
                         Quartz.IScheduler sched,
                         ILogger <SpiderController> logger)
 {
     _logger    = logger;
     _dbContext = dbContext;
     _sched     = sched;
     _options   = options;
 }
Пример #9
0
        public QuartzCronSchedulerViaInternalSchedule(Options options, List <Schedule> schedule, IJobFactory jobFactory, ILoggerFactoryAdapter loggerFactory)
        {
            _options              = options;
            _schedule             = schedule;
            _scheduler            = StdSchedulerFactory.GetDefaultScheduler();
            _scheduler.JobFactory = jobFactory;

            LogManager.Adapter = loggerFactory;
            _logger            = LogManager.GetLogger("Quartz.Net");
        }
        public QuartzCronSchedulerViaCommandLine(Options options, IJobFactory jobFactory, ILoggerFactory loggerFactory)
        {
            _options              = options;
            _scheduler            = StdSchedulerFactory.GetDefaultScheduler().Result;
            _scheduler.JobFactory = jobFactory;

            Quartz.LogContext.SetCurrentLogProvider(loggerFactory);

            _logger = loggerFactory.CreateLogger("Quartz.Net");
        }
Пример #11
0
        /// <summary>
        /// 启动
        /// </summary>
        public async Task StartAsync()
        {
            _scheduler = await GetScheduler();

            if (_scheduler.IsStarted)
            {
                return;
            }
            await _scheduler.Start();
        }
Пример #12
0
        public Scheduler(ILog log)
        {
            _scheduler = StdSchedulerFactory
                         .GetDefaultScheduler()
                         .ConfigureAwait(true)
                         .GetAwaiter()
                         .GetResult();

            _log = log;
        }
Пример #13
0
        public override void Update(Quartz.IScheduler scheduler)
        {
            this.Scheduler = scheduler;

            this.Calendars = scheduler.GetCalendarNames().Select(n => new {
                Name     = n,
                Calendar = scheduler.GetCalendar(n)
            }).ToDictionary(n => n.Name, n => n.Calendar);

            this.NotifyOfPropertyChange(() => this.Calendars);
        }
Пример #14
0
        // Helpers
        private async Task <bool> InitialiseScheduler(CancellationToken cancellationToken = default)
        {
            // First time initialization of Scheduler
            quartzScheduler = await schedulerFactory.GetScheduler(cancellationToken);

            quartzScheduler.JobFactory = jobFactory;
            quartzScheduler.ListenerManager.AddJobListener(new JobListener(this));

            // Load configuration
            return(await LoadConfiguration(cancellationToken));
        }
Пример #15
0
 public override void Update(Quartz.IScheduler scheduler)
 {
     this.Scheduler = scheduler;
     //NOT SUPPORT
     this.TriggerListeners   = scheduler.ListenerManager.GetTriggerListeners().ToList();
     this.SchedulerListeners = scheduler.ListenerManager.GetSchedulerListeners().ToList();
     this.JobListeners       = scheduler.ListenerManager.GetJobListeners().ToList();
     this.NotifyOfPropertyChange(() => this.TriggerListeners);
     this.NotifyOfPropertyChange(() => this.SchedulerListeners);
     this.NotifyOfPropertyChange(() => this.JobListeners);
 }
Пример #16
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="dellist"></param>
        public static void deleteJob(Quartz.IScheduler scheduler, List <Config> dellist)
        {
            IList <JobKey> jlist = new List <Quartz.JobKey>();

            foreach (var it in dellist)
            {
                JobKey key = new JobKey(it.jobname, it.groupname);
                jlist.Add(key);
            }

            scheduler.DeleteJobs(jlist);
        }
Пример #17
0
        public async Task <bool> TryInitWithSchedule(IBot owner, string cronExpression)
        {
            Owner = owner;
            LogProvider.SetCurrentLogProvider(new ConsoleLogProvider());
            var factory = new StdSchedulerFactory();

            scheduler = await factory.GetScheduler();

            bool ok = await TrySetSchedule(cronExpression, scheduler);

            return(ok);
        }
Пример #18
0
 public IJob NewJob(TriggerFiredBundle bundle, Quartz.IScheduler scheduler)
 {
     try
     {
         var x = NinjectBootstrapper.Get(bundle.JobDetail.JobType);
         return((IJob)x);
     }
     catch (Exception err)
     {
         this.EventReporter.ExceptionForObject(err, bundle.JobDetail);
         throw;
     }
 }
Пример #19
0
 public virtual void Initialize()
 {
     try
     {
         schedulerFactory = CreateSchedulerFactory();
         scheduler        = GetScheduler();
     }
     catch (Exception e)
     {
         logger.Error("Server initialization failed:" + e.Message, e);
         throw;
     }
 }
Пример #20
0
 public ExportDataService()
 {
     Thread.Sleep(5000);
     try
     {
         InitializeComponent();
         Quartz.ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
         scheduler = schedulerFactory.GetScheduler();
     }
     catch (Exception ex)
     {
         LogHelper.LogWriter("异常啦:" + ex);
     }
 }
        public IJob NewJob(TriggerFiredBundle bundle, Quartz.IScheduler scheduler)
        {
            var scope = scopeFactory.CreateScope();
            var job   = scope.ServiceProvider.GetService(bundle.JobDetail.JobType) as IJob;

            if (job == null)
            {
                logger.LogError($"Could not create job of type: {bundle.JobDetail.JobType}, job will be paused!");
                scheduler.PauseJob(bundle.JobDetail.Key);
                throw new ArgumentException($"Could not create job of type: {bundle.JobDetail.JobType}");
            }
            this.scopes.Add(job.GetHashCode(), scope);

            return(job);
        }
Пример #22
0
        /// <summary>
        ///添加一箱
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="item"></param>
        private static void addjob(Quartz.IScheduler scheduler, Core.Config item)
        {
            Assembly assembly = Assembly.Load(item.assemblyname);
            Type     type     = assembly.GetType(item.@namespace);


            IJobDetail job = JobBuilder.Create(type)
                             .WithIdentity(item.jobname, item.groupname).Build(); // name "myJob", group "group1"

            var trigger = addTriger(item);



            scheduler.ScheduleJob(job, trigger.Build());
        }
Пример #23
0
        public void Stop()
        {
            if (_scheduler == null)
            {
                return;
            }

            if (_scheduler.Shutdown(waitForJobsToComplete: true).Wait(30000))
            {
                _scheduler = null;
            }
            else
            {
            }
            _logger.LogCritical("Schedule job upload as application stopped");
        }
Пример #24
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="modilist"></param>

        public static void modiJob(Quartz.IScheduler scheduler, List <Config> modilist)
        {
            //   scheduler.GetTrigger(new TriggerKey(

            foreach (var item in modilist)
            {
                //var old = scheduler.GetTrigger(new TriggerKey(item.jobname + "trigger", "触发器组"));
                //if (old == null)
                //    return;

                //var newtrigger = addTriger(item).Build();
                //scheduler.RescheduleJob(old.Key, newtrigger);

                JobKey key = new JobKey(item.jobname, item.groupname);
                scheduler.DeleteJob(key);
                addjob(scheduler, item);
            }
        }
Пример #25
0
        public Scheduler()
        {
            this.tirggers = new Dictionary <IScheduledJob, TriggerKey>();

            //configuring logger
            LogProvider.SetCurrentLogProvider(new SchedulerLogProvider());

            // Grab the Scheduler instance from the Factory
            NameValueCollection props = new NameValueCollection
            {
                { "quartz.serializer.type", "binary" }
            };
            StdSchedulerFactory factory = new StdSchedulerFactory(props);

            this.scheduler = factory.GetScheduler().Result;

            // and start it off
            scheduler.Start().Wait();
        }
Пример #26
0
 public IJob NewJob(TriggerFiredBundle bundle, Quartz.IScheduler scheduler)
 {
     try
     {
         var    genericType = typeof(AutofacJobWrapper <>);
         Type[] typeArgs    = { bundle.JobDetail.JobType };
         var    actualType  = genericType.MakeGenericType(typeArgs);
         var    x           = this.Context.Resolve(actualType);
         return((IJob)x);
     }
     catch (Exception err)
     {
         //using(var scope = this.Context.BeginLifetimeScope())
         //{
         //	var reporter = scope.Resolve<IEventReporter>();
         //	reporter.ExceptionForObject(err, bundle.JobDetail);
         //}
         throw;
     }
 }
        public void Start()
        {
            Log.Debug("Starting LIM Scheduler");
            var properties = new NameValueCollection();
            properties["quartz.scheduler.instanceName"] = "RemoteServer";

            properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"] = "5";
            properties["quartz.threadPool.threadPriority"] = "Normal";

            properties["quartz.plugin.xml.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz";
            properties["quartz.plugin.xml.fileNames"] = "jobs.xml";

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory(properties);
            _scheduler = schedulerFactory.GetScheduler();
            _scheduler.JobFactory = new JobFactory(_container);

            var bus = _container.Resolve<IAdvancedBus>();

            var senderQueue = bus.QueueDeclare("DataPlatform.Integration.Sender");
            var senderExchange = bus.ExchangeDeclare("DataPlatform.Integration.Sender", ExchangeType.Fanout);
            bus.Bind(senderExchange, senderQueue, string.Empty);

            var receiverQueue = bus.QueueDeclare("DataPlatform.Integration.Receiver");
            var receiverExchange = bus.ExchangeDeclare("DataPlatform.Integration.Receiver", ExchangeType.Fanout);
            bus.Bind(receiverExchange, receiverQueue, string.Empty);

            bus.Consume(senderQueue,
                q =>
                    q.Add<PackageResponseMessage>(
                        (message, info) => new SenderConsumers<PackageResponseMessage>(message, _container)));

            bus.Consume(receiverQueue,
                q =>
                    q.Add<PackageConfigurationMessage>(
                        (message, info) => new ReceiverConsumers<PackageConfigurationMessage>(message, _container)));

            _scheduler.Start();

            Log.Debug("LIM Scheduler has started");
        }
Пример #28
0
        protected override void OnStart(string[] args)
        {
            Tools.Logger.LogToFile(new Models.LogEntry(0, "OnStart", "Service Started Successfully"));
            // First, initialize Quartz.NET as usual. In this sample app I'll configure Quartz.NET by code.
            var schedulerFactory = new StdSchedulerFactory();
            scheduler = schedulerFactory.GetScheduler();
            scheduler.Start();

            scheduler.ListenerManager.AddJobListener(new Listeners.GlobalJobListener());
            scheduler.ListenerManager.AddTriggerListener(new Listeners.GlobalTriggerListener());

            // A sample trigger and job
            var SoapTrigger = TriggerBuilder.Create()
               .WithIdentity("CheckTrigger").WithSchedule(Quartz.SimpleScheduleBuilder.RepeatMinutelyForever(2))
               .StartNow()
               .Build();
            var SoapJob = new JobDetailImpl("SoapJob", "Soap", typeof(Jobs.SoapJob));
            scheduler.ScheduleJob(SoapJob, SoapTrigger);

            scheduler.AddCalendar("myCalendar", new Calendars.RiskCalendar { Description = "Risk Calendar" }, false, false);
        }
Пример #29
0
        public async Task <string> Start()
        {
            //2、通过调度工厂获得调度器
            _scheduler = await _schedulerFactory.GetScheduler();

            _scheduler.JobFactory = this._iocJobfactory;//  替换默认工厂
            //3、开启调度器
            await _scheduler.Start();

            //4、创建一个触发器
            var trigger = TriggerBuilder.Create()
                          .WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever())//每两秒执行一次
                          .Build();
            //5、创建任务
            var jobDetail = JobBuilder.Create <OpcServerSyncjob>()
                            .WithIdentity("job", "group")
                            .Build();
            //6、将触发器和任务器绑定到调度器中
            await _scheduler.ScheduleJob(jobDetail, trigger);

            return(await Task.FromResult("将触发器和任务器绑定到调度器中完成"));
        }
Пример #30
0
        public void Start()
        {
            var cronExpression = ConfigurationManager.AppSettings["CronSchedule"];

            if (!CronExpression.IsValidExpression(cronExpression))
            {
                _log.Warn("Couldn't start the scheduler. Cron expression is invalid.");
                return;
            }

            if (string.IsNullOrEmpty(cronExpression))
            {
                _log.Warn("No schedule set.");
                return;
            }

            _log.Info("Starting the scheduler...");

            _quartzScheduler            = _schedulerFactory.GetScheduler();
            _quartzScheduler.JobFactory = new NinjectJobFactory(_resolutionRoot);
            _quartzScheduler.Start();

            var job = JobBuilder.Create <PushNotificationJob>()
                      .WithIdentity("job1", "group1")
                      .Build();

            var trigger = TriggerBuilder.Create()
                          .WithIdentity("trigger1", "group1")
                          .StartNow()
                          .WithSchedule(CronScheduleBuilder.CronSchedule(cronExpression))
                          //.WithSimpleSchedule(x => x
                          //    .WithIntervalInSeconds(120)
                          //    .RepeatForever())
                          //       .ForJob(job)
                          .Build();

            _quartzScheduler.ScheduleJob(job, trigger);
        }
Пример #31
0
        private async Task <bool> TrySetSchedule(string cronExpression, Quartz.IScheduler scheduler)
        {
            if (!CronExpression.IsValidExpression(cronExpression))
            {
                return(false);
            }

            IJobDetail job = JobBuilder.Create <PostWeeklySeedJob>()
                             .WithIdentity("WeeklySeedJob", "Group1")
                             .Build();

            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("schedule", "Group1")
                               .StartNow()
                               .WithCronSchedule(cronExpression)
                               .Build();

            await scheduler.Clear();

            await scheduler.ScheduleJob(job, trigger);

            return(true);
        }
        public void Start()
        {
            Log.Debug("Starting Cache Worker");
            var properties = new NameValueCollection();
            properties["quartz.scheduler.instanceName"] = "RemoteServer";


            properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"] = "5";
            properties["quartz.threadPool.threadPriority"] = "Normal";


            properties["quartz.plugin.xml.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz";
            properties["quartz.plugin.xml.fileNames"] = "jobs.xml";

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory(properties);
            _scheduler = schedulerFactory.GetScheduler();
            _scheduler.JobFactory = new JobFactory(_container);

            _scheduler.Start();

            _bus = _container.Resolve<IAdvancedBus>();
            var receiverQueue = _bus.QueueDeclare("DataPlatform.DataProvider.Cache.Receiver");
            var receiverExchange = _bus.ExchangeDeclare("DataPlatform.DataProvider.Cache.Receiver", ExchangeType.Fanout);
            _bus.Bind(receiverExchange, receiverQueue, string.Empty);

            _bus.Consume(receiverQueue, q => q
                .Add<ClearCacheCommand>(
                (message, info) => new ReceiverConsumers<ClearCacheCommand>(message, _container))
                .Add<RefreshCacheCommand>(
                (message, info) => new ReceiverConsumers<RefreshCacheCommand>(message, _container))
                .Add<RestartCacheDataStoreCommand>(
                (message, info) => new ReceiverConsumers<RestartCacheDataStoreCommand>(message, _container)));

            Log.Debug("Cache Worker has started");
        }
Пример #33
0
        }   // End Constructor

        public async System.Threading.Tasks.Task StartJobs(System.Threading.CancellationToken stoppingToken)
        {
            this._stopppingToken   = stoppingToken;
            this._schedulerFactory = new Quartz.Impl.StdSchedulerFactory();
            this._scheduler        = await this._schedulerFactory.GetScheduler();

            await this._scheduler.Start();

            Quartz.IJobDetail job1 = Quartz.JobBuilder.Create <Job1>()
                                     .WithIdentity("job1", "gtoup")
                                     .Build();

            Quartz.ITrigger trigger1 = Quartz.TriggerBuilder.Create()
                                       .WithIdentity("trigger_10_sec", "group")
                                       .StartNow()
                                       .WithSimpleSchedule(x => x
                                                           .WithIntervalInSeconds(10)
                                                           .RepeatForever())
                                       .Build();

            Quartz.IJobDetail job2 = Quartz.JobBuilder.Create <Job2>()
                                     .WithIdentity("job2", "group")
                                     .Build();

            Quartz.ITrigger trigger2 = Quartz.TriggerBuilder.Create()
                                       .WithIdentity("trigger_20_sec", "group")
                                       .StartNow()
                                       .WithSimpleSchedule(x => x
                                                           .WithIntervalInSeconds(20)
                                                           .RepeatForever())
                                       .Build();

            await this._scheduler.ScheduleJob(job1, trigger1, this._stopppingToken);

            await this._scheduler.ScheduleJob(job2, trigger2, this._stopppingToken);
        } // End Task StartJobs
Пример #34
0
 private QuartzWrapper()
 {
     var schedulerFact = new Quartz.Impl.StdSchedulerFactory();
     _scheduler = schedulerFact.GetScheduler();
     _scheduler.Start();
 }