public void TestTriggerBuilder()
        {
            ITrigger trigger = TriggerBuilder.Create()
                               .Build();

            Assert.IsTrue(trigger.Key.Name != null, "Expected non-null trigger name ");
            Assert.IsTrue(trigger.Key.Group.Equals(JobKey.DefaultGroup), "Unexpected trigger group: " + trigger.Key.Group);
            Assert.IsTrue(trigger.JobKey == null, "Unexpected job key: " + trigger.JobKey);
            Assert.IsTrue(trigger.Description == null, "Unexpected job description: " + trigger.Description);
            Assert.IsTrue(trigger.Priority == TriggerConstants.DefaultPriority, "Unexpected trigger priority: " + trigger.Priority);
            Assert.That(trigger.StartTimeUtc.DateTime, Is.EqualTo(DateTimeOffset.UtcNow.DateTime).Within(TimeSpan.FromSeconds(1)), "Unexpected start-time: " + trigger.StartTimeUtc);
            Assert.IsTrue(trigger.EndTimeUtc == null, "Unexpected end-time: " + trigger.EndTimeUtc);

            DateTimeOffset stime = DateBuilder.EvenSecondDateAfterNow();

            trigger = TriggerBuilder.Create()
                      .WithIdentity("t1")
                      .WithDescription("my description")
                      .WithPriority(2)
                      .EndAt(DateBuilder.FutureDate(10, IntervalUnit.Week))
                      .StartAt(stime)
                      .Build();

            Assert.IsTrue(trigger.Key.Name.Equals("t1"), "Unexpected trigger name " + trigger.Key.Name);
            Assert.IsTrue(trigger.Key.Group.Equals(JobKey.DefaultGroup), "Unexpected trigger group: " + trigger.Key.Group);
            Assert.IsTrue(trigger.JobKey == null, "Unexpected job key: " + trigger.JobKey);
            Assert.IsTrue(trigger.Description.Equals("my description"), "Unexpected job description: " + trigger.Description);
            Assert.IsTrue(trigger.Priority == 2, "Unexpected trigger priority: " + trigger);
            Assert.IsTrue(trigger.StartTimeUtc.Equals(stime), "Unexpected start-time: " + trigger.StartTimeUtc);
            Assert.IsTrue(trigger.EndTimeUtc != null, "Unexpected end-time: " + trigger.EndTimeUtc);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            NameValueCollection properties = new NameValueCollection();

            properties["quartz.scheduler.instanceName"] = "RemoteServer1"; //"RemoteServer";

            // set thread pool info
            properties["quartz.threadPool.type"]           = "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"]    = "5";
            properties["quartz.threadPool.threadPriority"] = "Normal";

            // set remoting exporter
            properties["quartz.scheduler.exporter.type"]        = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
            properties["quartz.scheduler.exporter.port"]        = "556";
            properties["quartz.scheduler.exporter.bindName"]    = "QuartzScheduler";
            properties["quartz.scheduler.exporter.channelType"] = "tcp";
            properties["quartz.scheduler.exporter.channelName"] = "httpQuartz";
            // reject non-local requests
            // properties["quartz.scheduler.exporter.rejectRemoteRequests"] = "true";

            ISchedulerFactory sf    = new StdSchedulerFactory(properties);
            IScheduler        sched = sf.GetScheduler();

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

            //log.Info("------- Not scheduling any Jobs - relying on a remote client to schedule jobs --");

            //log.Info("------- Starting Scheduler ----------------");
            Console.WriteLine("------- Starting Scheduler ----------------");

            DateTimeOffset runTime = DateBuilder.EvenSecondDateAfterNow();

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

            // Trigger the job to run on the next round minute
            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("trigger1", "group1")
                               .StartAt(runTime)
                               .WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever())
                               .Build();

            // Tell quartz to schedule the job using our trigger
            sched.ScheduleJob(job, trigger);
            Console.WriteLine(string.Format("{0} will run at: {1}", job.Key, runTime.ToString("r")));

            // start the schedule
            sched.Start();
        }
Beispiel #3
0
        public void TestTriggerBuilder()
        {
            IJobDetail job = JobBuilder.NewJob()
                             .OfType <TestJob>()
                             .WithIdentity("j1")
                             .StoreDurably()
                             .Build();

            ITrigger trigger = TriggerBuilder.Create()
                               .Build();

            Assert.IsTrue(trigger.Key.Name != null, "Expected non-null trigger name ");
            Assert.IsTrue(trigger.Key.Group.Equals(JobKey.DefaultGroup), "Unexpected trigger group: " + trigger.Key.Group);
            Assert.IsTrue(trigger.JobKey == null, "Unexpected job key: " + trigger.JobKey);
            Assert.IsTrue(trigger.Description == null, "Unexpected job description: " + trigger.Description);
            Assert.IsTrue(trigger.Priority == TriggerConstants.DefaultPriority, "Unexpected trigger priority: " + trigger.Priority);
            Assert.IsTrue(trigger.StartTimeUtc != null, "Unexpected start-time: " + trigger.StartTimeUtc);
            Assert.IsTrue(trigger.EndTimeUtc == null, "Unexpected end-time: " + trigger.EndTimeUtc);

            DateTimeOffset stime = DateBuilder.EvenSecondDateAfterNow();

            trigger = TriggerBuilder.Create()
                      .WithIdentity("t1")
                      .WithDescription("my description")
                      .WithPriority(2)
                      .EndAt(DateBuilder.FutureDate(10, DateBuilder.IntervalUnit.Week))
                      .StartAt(stime)
                      .Build();

            Assert.IsTrue(trigger.Key.Name.Equals("t1"), "Unexpected trigger name " + trigger.Key.Name);
            Assert.IsTrue(trigger.Key.Group.Equals(JobKey.DefaultGroup), "Unexpected trigger group: " + trigger.Key.Group);
            Assert.IsTrue(trigger.JobKey == null, "Unexpected job key: " + trigger.JobKey);
            Assert.IsTrue(trigger.Description.Equals("my description"), "Unexpected job description: " + trigger.Description);
            Assert.IsTrue(trigger.Priority == 2, "Unexpected trigger priortiy: " + trigger);
            Assert.IsTrue(trigger.StartTimeUtc.Equals(stime), "Unexpected start-time: " + trigger.StartTimeUtc);
            Assert.IsTrue(trigger.EndTimeUtc != null, "Unexpected end-time: " + trigger.EndTimeUtc);
        }