示例#1
0
        public void MisfireTriggerTest()
        {
            Debug.WriteLine("------- Scheduling Jobs -------------------");

            var semHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

            // Set the job run time.
            DateTime rangeStart  = DateTime.UtcNow;
            DateTime runTime     = rangeStart.AddSeconds(1);
            var      runSchedule = new OneTimeSchedule(runTime, TimeSpan.Zero);

            // Define the job and tie it to our HelloJob class.
            JobDataMap jobDataMap = new JobDataMap((IDictionary <string, object>) new Dictionary <string, object> {
                { "SemHandle", semHandle }
            });

            IJobDetail job = JobBuilder.Create <HelloJob>()
                             .WithDescription("job1")
                             .WithIdentity("job1", "group1")
                             .UsingJobData(jobDataMap)
                             .Build();

            // Trigger the job to run on the set time.
            var trigger = TriggerBuilder.Create()
                          .WithIdentity("trigger1", "group1")
                          .WithItinerarySchedule(runSchedule, rangeStart, x => x.WithMisfireHandlingInstructionFireAndProceed())
                          .Build();

            // Tell Quartz to schedule the job using our trigger.
            sched.ScheduleJob(job, trigger);
            var firstEvent = runSchedule.GetRange(rangeStart, DateTime.MaxValue).First();

            Debug.WriteLine(string.Format("{0} will start at: {1}", job.Description, firstEvent.StartTime.ToString("r")));

            // Start up the scheduler.
            sched.Start();
            Debug.WriteLine("------- Started Scheduler -----------------");

            // Wait long enough so that the scheduler as an opportunity to
            // run the job.
            Debug.WriteLine("------- PauseAll(), wait 4s -------------");

            sched.PauseAll();
            Thread.Sleep(4000);
            Debug.WriteLine("------- ResumeAll(), expect job to run immediately -------------");
            sched.ResumeAll();

            // TODO: What does it take to get Quartz to drop a trigger event?
            Debug.WriteLine("------- Waiting a few seconds... -------------");
            Assert.IsTrue(semHandle.WaitOne(5000));
        }
示例#2
0
        public void OneTimeScheduleTriggerTest()
        {
            Debug.WriteLine("------- Scheduling Jobs -------------------");

            var semHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

            // Set the job run time.
            DateTime rangeStart  = DateTime.UtcNow;
            DateTime runTime     = rangeStart.AddSeconds(1);
            var      runSchedule = new OneTimeSchedule(runTime, TimeSpan.Zero);

            // Define the job and tie it to our HelloJob class.
            JobDataMap jobDataMap = new JobDataMap((IDictionary <string, object>) new Dictionary <string, object> {
                { "SemHandle", semHandle }
            });

            IJobDetail job = JobBuilder.Create <HelloJob>()
                             .WithDescription("job1")
                             .WithIdentity("job1", "group1")
                             .UsingJobData(jobDataMap)
                             .Build();

            // Trigger the job to run on the set time.
            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("trigger1", "group1")
                               .WithItinerarySchedule(runSchedule, rangeStart)
                               .Build();

            // Tell Quartz to schedule the job using our trigger.
            sched.ScheduleJob(job, trigger);
            var firstEvent = runSchedule.GetRange(rangeStart, DateTime.MaxValue).First();

            Debug.WriteLine(string.Format("{0} will start at: {1}", job.Description, firstEvent.StartTime.ToString("r")));

            // Start up the scheduler.
            sched.Start();
            Debug.WriteLine("------- Started Scheduler -----------------");

            // Wait long enough so that the scheduler as an opportunity to
            // run the job.
            Debug.WriteLine("------- Waiting a few seconds... -------------");

            // Wait for job to signal.
            Assert.IsTrue(semHandle.WaitOne(5000));
        }
        public void MisfireTriggerTest()
        {
            Debug.WriteLine("------- Scheduling Jobs -------------------");

             var semHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

             // Set the job run time.
             DateTime rangeStart = DateTime.UtcNow;
             DateTime runTime = rangeStart.AddSeconds(1);
             var runSchedule = new OneTimeSchedule(runTime, TimeSpan.Zero);

             // Define the job and tie it to our HelloJob class.
             JobDetail job = new JobDetail("job1", "group1", typeof(HelloJob));
             job.JobDataMap["SemHandle"] = semHandle;

             // Trigger the job to run on the set time.
             var trigger = new ItineraryTrigger("trigger1", "group1", runSchedule, rangeStart);
             trigger.MisfireInstruction = ItineraryTriggerMisfireInstruction.RescheduleNowWithExistingCount;

             // Tell Quartz to schedule the job using our trigger.
             sched.ScheduleJob(job, trigger);
             var firstEvent = runSchedule.GetRange(rangeStart, DateTime.MaxValue).First();
             Debug.WriteLine(string.Format("{0} will start at: {1}", job.FullName, firstEvent.StartTime.ToString("r")));

             // Start up the scheduler.
             sched.Start();
             Debug.WriteLine("------- Started Scheduler -----------------");

             // Wait long enough so that the scheduler as an opportunity to
             // run the job.
             Debug.WriteLine("------- PauseAll(), wait 4s -------------");

             sched.PauseAll();
             Thread.Sleep(4000);
             Debug.WriteLine("------- ResumeAll(), expect job to run immediately -------------");
             sched.ResumeAll();

             // TODO: What does it take to get Quartz to drop a trigger event?
             Debug.WriteLine("------- Waiting a few seconds... -------------");
             Assert.IsTrue(semHandle.WaitOne(5000));
        }
        public void OneTimeScheduleTriggerTest()
        {
            Debug.WriteLine("------- Scheduling Jobs -------------------");

             var semHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

             // Set the job run time.
             DateTime rangeStart = DateTime.UtcNow;
             DateTime runTime = rangeStart.AddSeconds(1);
             var runSchedule = new OneTimeSchedule(runTime, TimeSpan.Zero);

             // Define the job and tie it to our HelloJob class.
             JobDetail job = new JobDetail("job1", "group1", typeof(HelloJob));
             job.JobDataMap["SemHandle"] = semHandle;

             // Trigger the job to run on the set time.
             var trigger = new ItineraryTrigger("trigger1", "group1", runSchedule, rangeStart);

             // Tell Quartz to schedule the job using our trigger.
             sched.ScheduleJob(job, trigger);
             var firstEvent = runSchedule.GetRange(rangeStart, DateTime.MaxValue).First();
             Debug.WriteLine(string.Format("{0} will start at: {1}", job.FullName, firstEvent.StartTime.ToString("r")));

             // Start up the scheduler.
             sched.Start();
             Debug.WriteLine("------- Started Scheduler -----------------");

             // Wait long enough so that the scheduler as an opportunity to
             // run the job.
             Debug.WriteLine("------- Waiting a few seconds... -------------");

             // Wait for job to signal.
             Assert.IsTrue(semHandle.WaitOne(5000));
        }
        public void MisfireTriggerTest()
        {
            Debug.WriteLine("------- Scheduling Jobs -------------------");

             var semHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

             // Set the job run time.
             DateTime rangeStart = DateTime.UtcNow;
             DateTime runTime = rangeStart.AddSeconds(1);
             var runSchedule = new OneTimeSchedule(runTime, TimeSpan.Zero);

             // Define the job and tie it to our HelloJob class.
             JobDataMap jobDataMap = new JobDataMap((IDictionary<string, object>)new Dictionary<string, object> {
            { "SemHandle", semHandle }
             });

             IJobDetail job = JobBuilder.Create<HelloJob>()
            .WithDescription("job1")
            .WithIdentity("job1", "group1")
            .UsingJobData(jobDataMap)
            .Build();

             // Trigger the job to run on the set time.
             var trigger = TriggerBuilder.Create()
            .WithIdentity("trigger1", "group1")
            .WithItinerarySchedule(runSchedule, rangeStart, x => x.WithMisfireHandlingInstructionFireAndProceed())
            .Build();

             // Tell Quartz to schedule the job using our trigger.
             sched.ScheduleJob(job, trigger);
             var firstEvent = runSchedule.GetRange(rangeStart, DateTime.MaxValue).First();
             Debug.WriteLine(string.Format("{0} will start at: {1}", job.Description, firstEvent.StartTime.ToString("r")));

             // Start up the scheduler.
             sched.Start();
             Debug.WriteLine("------- Started Scheduler -----------------");

             // Wait long enough so that the scheduler as an opportunity to
             // run the job.
             Debug.WriteLine("------- PauseAll(), wait 4s -------------");

             sched.PauseAll();
             Thread.Sleep(4000);
             Debug.WriteLine("------- ResumeAll(), expect job to run immediately -------------");
             sched.ResumeAll();

             // TODO: What does it take to get Quartz to drop a trigger event?
             Debug.WriteLine("------- Waiting a few seconds... -------------");
             Assert.IsTrue(semHandle.WaitOne(5000));
        }
        public void OneTimeScheduleTriggerTest()
        {
            Debug.WriteLine("------- Scheduling Jobs -------------------");

             var semHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

             // Set the job run time.
             DateTime rangeStart = DateTime.UtcNow;
             DateTime runTime = rangeStart.AddSeconds(1);
             var runSchedule = new OneTimeSchedule(runTime, TimeSpan.Zero);

             // Define the job and tie it to our HelloJob class.
             JobDataMap jobDataMap = new JobDataMap((IDictionary<string, object>)new Dictionary<string, object> {
            { "SemHandle", semHandle }
             });

             IJobDetail job = JobBuilder.Create<HelloJob>()
            .WithDescription("job1")
            .WithIdentity("job1", "group1")
            .UsingJobData(jobDataMap)
            .Build();

             // Trigger the job to run on the set time.
             ITrigger trigger = TriggerBuilder.Create()
            .WithIdentity("trigger1", "group1")
            .WithItinerarySchedule(runSchedule, rangeStart)
            .Build();

             // Tell Quartz to schedule the job using our trigger.
             sched.ScheduleJob(job, trigger);
             var firstEvent = runSchedule.GetRange(rangeStart, DateTime.MaxValue).First();
             Debug.WriteLine(string.Format("{0} will start at: {1}", job.Description, firstEvent.StartTime.ToString("r")));

             // Start up the scheduler.
             sched.Start();
             Debug.WriteLine("------- Started Scheduler -----------------");

             // Wait long enough so that the scheduler as an opportunity to
             // run the job.
             Debug.WriteLine("------- Waiting a few seconds... -------------");

             // Wait for job to signal.
             Assert.IsTrue(semHandle.WaitOne(5000));
        }