Search code examples
c#nhibernatequartz-schedulerquartz.net

Delay crone trigger (diffrent first start date) in quartz


I've almost finished simple application in c# with quartz which run some SQL queries periodically.

I have a question, is it possible to create cron trigger which start job at specific date and after this date do some jobs periodically.

here is my code:

                    IJobDetails myJob = new JobDetails(); //This Constructor needs to be parameterless i nic na to nie poradzimy
                    JobDetailImpl jobDetail = new JobDetailImpl(name, gruoupName, myJob.GetType());
                    //dodawanie parametru
                    jobDetail.JobDataMap.Add("addParam", item);
                    //////
                    CronTriggerImpl trigger = new CronTriggerImpl();
                    trigger.Name = triggerName;
                    trigger.Group = grupa;
                    trigger.CronExpressionString = "0 10 14-15 8 8 ?";

                    try
                    {
                        _scheduler.ScheduleJob(jobDetail, trigger);
                    }
                    catch
                    {
                        MessageBox.Show("INVALID TRIGGER. JOB CANCELED");
                    }
                    DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc().Value.AddHours(2);

                    Console.WriteLine("Job o jobs_id=" + item.jobs_id + " start:" +     nextFireTime.Value);

For example: Today is 1.08.2013 and today i want to create crone trigger which start at 8.08.2013 and fires SQL query every day from 2:00pm to 3:00pm every 10minutes.

At the moment I know how to make crone trigger which start 8.08.2013 and run once, and know how to create second crone trigger which run every day from 2:00pm to 3:00pm every 10minutes but i still can not figure out how to marge this 2 crone triggers and create one: which start at 8.08.2013, run everyday after 8.08.2013 and fires SQL query every day from 2:00pm to 3:00pm for each 10minutes.

I tried use:

      trigger.FinalFireTimeUtc(someDate);
      trigger.SetNextFireTimeUtc(someDate)

But without any positive result. Job fires as its cronExpressionString says.

Many thanks in advance for help.


Solution

  • Thank You lenimall for answer. I check method StatTimeUTC but it returns start datetime value, not setting it. I have found blog which proffs Quartz is not capable of running jobs at the time when you desired. http://nurkiewicz.blogspot.com/2012/04/quartz-scheduler-misfire-instructions.html Anyway, many thanks for help!