Ejemplo n.º 1
0
        /// <summary>
        /// Add the Jobs and Triggers defined in the given map of <see cref="JobSchedulingBundle" />
        /// s to the given scheduler.
        /// </summary>
        /// <param name="jobBundles">The job bundles.</param>
        /// <param name="sched">The sched.</param>
        /// <param name="overwriteExistingJobs">if set to <c>true</c> [over write existing jobs].</param>
        public virtual void ScheduleJobs(IDictionary jobBundles, IScheduler sched, bool overwriteExistingJobs)
        {
            Log.Info(string.Format(CultureInfo.InvariantCulture, "Scheduling {0} parsed jobs.", jobsToSchedule.Count));

            foreach (CalendarBundle bndle in calsToSchedule)
            {
                AddCalendar(sched, bndle);
            }

            foreach (JobSchedulingBundle bndle in jobsToSchedule)
            {
                ScheduleJob(bndle, sched, overwriteExistingJobs);
            }

            foreach (IJobListener listener in listenersToSchedule)
            {
                Log.Info(string.Format(CultureInfo.InvariantCulture, "adding listener {0} of type {1}", listener.Name, listener.GetType().FullName));
                sched.AddJobListener(listener);
            }

            foreach (ITriggerListener listener in triggerListenersToSchedule)
            {
                Log.Info(string.Format(CultureInfo.InvariantCulture, "adding listener {0} of type {1}", listener.Name, listener.GetType().FullName));
                sched.AddTriggerListener(listener);
            }
            Log.Info(string.Format(CultureInfo.InvariantCulture, "{0} scheduled jobs.", jobBundles.Count));
        }
Ejemplo n.º 2
0
        public virtual void Run()
        {
            ILog log = LogManager.GetLogger(typeof(ListenerExample));

            log.Info("------- Initializing ----------------------");

            // First we must get a reference to a scheduler
            ISchedulerFactory sf    = new StdSchedulerFactory();
            IScheduler        sched = sf.GetScheduler();

            log.Info("------- Initialization Complete -----------");

            log.Info("------- Scheduling Jobs -------------------");

            // schedule a job to run immediately
            JobDetail     job     = new JobDetail("job1", "group1", typeof(SimpleJob1));
            SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1", DateTime.UtcNow, null, 0, TimeSpan.Zero);

            // Set up the listener
            IJobListener listener = new Job1Listener();

            sched.AddJobListener(listener);

            // make sure the listener is associated with the job
            job.AddJobListener(listener.Name);

            // schedule the job to run
            sched.ScheduleJob(job, trigger);

            // All of the jobs have been added to the scheduler, but none of the jobs
            // will run until the scheduler has been started
            log.Info("------- Starting Scheduler ----------------");
            sched.Start();

            // wait 30 seconds:
            // note:  nothing will run
            log.Info("------- Waiting 30 seconds... --------------");
            try
            {
                // wait 30 seconds to show jobs
                Thread.Sleep(TimeSpan.FromSeconds(30));
                // executing...
            }
            catch (ThreadInterruptedException)
            {
            }


            // shut down the scheduler
            log.Info("------- Shutting Down ---------------------");
            sched.Shutdown(true);
            log.Info("------- Shutdown Complete -----------------");

            SchedulerMetaData metaData = sched.GetMetaData();

            log.Info(string.Format("Executed {0} jobs.", metaData.NumJobsExecuted));
        }
Ejemplo n.º 3
0
        public JobHandler()
        {
            JobScheduler.Injectors.ServiceRegister.Initial();
            ISchedulerFactory schedFact = new StdSchedulerFactory();

            _scheduler = schedFact.GetScheduler();
            _scheduler.AddJobListener(this);
            _scheduler.Start();
        }
Ejemplo n.º 4
0
        public void TestSchedulerFactoryObjectWithListeners()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            IScheduler scheduler = (IScheduler)mockery.CreateMock(typeof(IScheduler));

            ISchedulerListener schedulerListener     = new TestSchedulerListener();
            IJobListener       globalJobListener     = new TestJobListener();
            IJobListener       jobListener           = new TestJobListener();
            ITriggerListener   globalTriggerListener = new TestTriggerListener();
            ITriggerListener   triggerListener       = new TestTriggerListener();

            Expect.Call(scheduler.JobFactory = (jobFactory));
            scheduler.AddSchedulerListener(schedulerListener);
            scheduler.AddGlobalJobListener(globalJobListener);
            scheduler.AddJobListener(jobListener);
            scheduler.AddGlobalTriggerListener(globalTriggerListener);
            scheduler.AddTriggerListener(triggerListener);
            scheduler.Start();
            scheduler.Shutdown(false);

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory             = (jobFactory);
            schedulerFactoryObject.SchedulerListeners     = (new ISchedulerListener[] { schedulerListener });
            schedulerFactoryObject.GlobalJobListeners     = (new IJobListener[] { globalJobListener });
            schedulerFactoryObject.JobListeners           = (new IJobListener[] { jobListener });
            schedulerFactoryObject.GlobalTriggerListeners = (new ITriggerListener[] { globalTriggerListener });
            schedulerFactoryObject.TriggerListeners       = (new ITriggerListener[] { triggerListener });
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }
Ejemplo n.º 5
0
        private void frmJobMonitor_Load(object sender, EventArgs e)
        {
            try
            {
                ISchedulerFactory schedFact = new StdSchedulerFactory();
                _scheduler = schedFact.GetScheduler();
                _scheduler.AddJobListener(this);
                _scheduler.Start();

                string version = ConfigurationManager.AppSettings["SecomVersion"];
                if (!string.IsNullOrEmpty(version))
                {
                    lblVersion.Text = version;
                }

                bsBatchQueue.DataSource = _lstBatchQueue;

                DateTime nextRunStart = DateTime.Now;
                DateTime nextRunEnd;
                if (nextRunStart.Minute < 55)
                {
                    nextRunEnd = nextRunStart.Date.AddHours(DateTime.Now.Hour + 1);
                }
                else
                {
                    nextRunEnd = nextRunStart.Date.AddHours(DateTime.Now.Hour + 2);
                }

                this.LoadBatchQueue(nextRunStart, nextRunEnd);
            }
            catch (Exception ex)
            {
                ErrorLogger.WriteErrorLog(DateTime.Now, ex);
                MessageBox.Show(this, ex.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
		/// <summary>
		/// Add the Jobs and Triggers defined in the given map of <see cref="JobSchedulingBundle" />
		/// s to the given scheduler.
		/// </summary>
		/// <param name="jobBundles">The job bundles.</param>
		/// <param name="sched">The sched.</param>
		/// <param name="overwriteExistingJobs">if set to <c>true</c> [over write existing jobs].</param>
		public virtual void ScheduleJobs(IDictionary jobBundles, IScheduler sched, bool overwriteExistingJobs)
		{
			Log.Info(string.Format(CultureInfo.InvariantCulture, "Scheduling {0} parsed jobs.", jobsToSchedule.Count));

			foreach (CalendarBundle bndle in calsToSchedule)
			{
				AddCalendar(sched, bndle);
			}

			foreach (JobSchedulingBundle bndle in jobsToSchedule)
			{
				ScheduleJob(bndle, sched, overwriteExistingJobs);
			}

			foreach (IJobListener listener in listenersToSchedule)
			{
				Log.Info(string.Format(CultureInfo.InvariantCulture, "adding listener {0} of type {1}", listener.Name, listener.GetType().FullName));
				sched.AddJobListener(listener);
			}

			foreach (ITriggerListener listener in triggerListenersToSchedule)
			{
				Log.Info(string.Format(CultureInfo.InvariantCulture, "adding listener {0} of type {1}", listener.Name, listener.GetType().FullName));
				sched.AddTriggerListener(listener);
			}
			Log.Info(string.Format(CultureInfo.InvariantCulture, "{0} scheduled jobs.", jobBundles.Count));
		}
Ejemplo n.º 7
0
 public void Initialize(string pluginName, IScheduler sched)
 {
     sched.AddTriggerListener(_triggerListener);
     sched.AddJobListener(_jobListener);
 }
Ejemplo n.º 8
0
        private void RunAdoJobStoreTest(string dbProvider, string connectionStringId,
                                        NameValueCollection extraProperties)
        {
            NameValueCollection properties = new NameValueCollection();

            properties["quartz.scheduler.instanceName"]      = "TestScheduler";
            properties["quartz.scheduler.instanceId"]        = "instance_one";
            properties["quartz.threadPool.type"]             = "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"]      = "10";
            properties["quartz.threadPool.threadPriority"]   = "Normal";
            properties["quartz.jobStore.misfireThreshold"]   = "60000";
            properties["quartz.jobStore.type"]               = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
            properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz";
            properties["quartz.jobStore.useProperties"]      = "false";
            properties["quartz.jobStore.dataSource"]         = "default";
            properties["quartz.jobStore.tablePrefix"]        = "QRTZ_";
            properties["quartz.jobStore.clustered"]          = clustered.ToString();

            if (extraProperties != null)
            {
                foreach (string key in extraProperties.Keys)
                {
                    properties[key] = extraProperties[key];
                }
            }

            if (connectionStringId == "SQLServer" || connectionStringId == "SQLite")
            {
                // if running MS SQL Server we need this
                properties["quartz.jobStore.lockHandler.type"] =
                    "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
            }

            properties["quartz.dataSource.default.connectionString"] = (string)dbConnectionStrings[connectionStringId];
            properties["quartz.dataSource.default.provider"]         = dbProvider;

            // First we must get a reference to a scheduler
            ISchedulerFactory sf    = new StdSchedulerFactory(properties);
            IScheduler        sched = sf.GetScheduler();

            try
            {
                if (clearJobs)
                {
                    CleanUp(sched);
                }

                if (scheduleJobs)
                {
                    ICalendar cronCalendar    = new CronCalendar("0/5 * * * * ?");
                    ICalendar holidayCalendar = new HolidayCalendar();

                    // QRTZNET-86
                    Trigger t = sched.GetTrigger("NonExistingTrigger", "NonExistingGroup");
                    Assert.IsNull(t);

                    AnnualCalendar cal = new AnnualCalendar();
                    sched.AddCalendar("annualCalendar", cal, false, true);

                    SimpleTrigger calendarsTrigger = new SimpleTrigger("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5));
                    calendarsTrigger.CalendarName = "annualCalendar";

                    JobDetail jd = new JobDetail("testJob", "test", typeof(NoOpJob));
                    sched.ScheduleJob(jd, calendarsTrigger);

                    // QRTZNET-93
                    sched.AddCalendar("annualCalendar", cal, true, true);

                    sched.AddCalendar("baseCalendar", new BaseCalendar(), false, true);
                    sched.AddCalendar("cronCalendar", cronCalendar, false, true);
                    sched.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true);
                    sched.AddCalendar("holidayCalendar", holidayCalendar, false, true);
                    sched.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true);
                    sched.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true);

                    sched.AddCalendar("cronCalendar", cronCalendar, true, true);
                    sched.AddCalendar("holidayCalendar", holidayCalendar, true, true);

                    Assert.IsNotNull(sched.GetCalendar("annualCalendar"));

                    JobDetail lonelyJob = new JobDetail("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob));
                    lonelyJob.Durable          = true;
                    lonelyJob.RequestsRecovery = true;
                    sched.AddJob(lonelyJob, false);
                    sched.AddJob(lonelyJob, true);

                    sched.AddJobListener(new DummyJobListener());
                    sched.AddTriggerListener(new DummyTriggerListener());

                    string schedId = sched.SchedulerInstanceId;

                    int count = 1;

                    JobDetail job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryJob));
                    job.AddJobListener(new DummyJobListener().Name);

                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = true;
                    SimpleTrigger trigger = new SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));

                    trigger.AddTriggerListener(new DummyTriggerListener().Name);
                    trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L);
                    sched.ScheduleJob(job, trigger);

                    // check that trigger was stored
                    Trigger persisted = sched.GetTrigger("trig_" + count, schedId);
                    Assert.IsNotNull(persisted);
                    Assert.IsTrue(persisted is SimpleTrigger);

                    count++;
                    job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));

                    trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(2000L));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryStatefulJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3));

                    trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4));

                    trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    CronTrigger ct = new CronTrigger("cron_trig_" + count, schedId, "0/10 * * * * ?");
                    ct.StartTimeUtc = DateTime.Now.AddMilliseconds(1000);

                    sched.ScheduleJob(job, ct);

                    count++;
                    job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    NthIncludedDayTrigger nt = new NthIncludedDayTrigger("cron_trig_" + count, schedId);
                    nt.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);
                    nt.N            = 1;

                    sched.ScheduleJob(job, nt);

                    sched.Start();

                    sched.PauseAll();

                    sched.ResumeAll();

                    sched.PauseJob("job_1", schedId);

                    sched.ResumeJob("job_1", schedId);

                    sched.PauseJobGroup(schedId);

                    Thread.Sleep(1000);

                    sched.ResumeJobGroup(schedId);

                    sched.PauseTrigger("trig_2", schedId);
                    sched.ResumeTrigger("trig_2", schedId);

                    sched.PauseTriggerGroup(schedId);

                    Assert.AreEqual(1, sched.GetPausedTriggerGroups().Count);

                    Thread.Sleep(1000);
                    sched.ResumeTriggerGroup(schedId);


                    Thread.Sleep(TimeSpan.FromSeconds(20));

                    sched.Standby();

                    Assert.IsNotEmpty(sched.GetCalendarNames());
                    Assert.IsNotEmpty(sched.GetJobNames(schedId));

                    Assert.IsNotEmpty(sched.GetTriggersOfJob("job_2", schedId));
                    Assert.IsNotNull(sched.GetJobDetail("job_2", schedId));

                    sched.RemoveJobListener(new DummyJobListener().Name);
                    sched.RemoveTriggerListener(new DummyTriggerListener().Name);

                    sched.DeleteCalendar("cronCalendar");
                    sched.DeleteCalendar("holidayCalendar");
                    sched.DeleteJob("lonelyJob", "lonelyGroup");
                }
            }
            finally
            {
                sched.Shutdown(false);
            }
        }