I'm attempting to implement Quartz.NET as a Windows Service in C#. My jobs are not triggering when I expect them to trigger… at all, actually, as far as I can tell?
I have My Job schedule running starting on the next even minute after the and running "minutely". However, when the next minute comes, I cannot seem to tell if anything actually runs.
I would assume that when my job runs, a CLI window would pop on job execution, and the Console operations would be visible, (I even put a Console.ReadKey()
in there to ensure the window isn't opening and closing so fast I can't see it), but as far as I can tell the schedule is simply not executing jobs.
I noticed that all the times are in UTC, and that the StartTimeUtc
will be set to the UTC time which is +6 hours from my local computer time, but I would also assume that the Quartz scheduler handles that by calculating execution time from my TimeZone setting, though I have no way that I know of to confirm that, or to confirm the ACTUAL times that my schedule is set for.
I imagine there's some way to setup the Common Logging assembly and utilize it to help me know what my status is, but I have yet to figure out what to do with that to enable a log of any sort for feedback from my Windows Service, aside from writing to the event log I created for it.
My OnStart function of my windows service
protected override void OnStart(string[] args)
{
eventLog.WriteEntry("--- STARTING eLoyalty Scheduler Service ---");
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
// construct job info
JobDetail jobDetail = new JobDetail("eLoyaltySchedulerService", null, typeof(PortalSchedulerJob));
jobDetail.JobDataMap["jobSays"] = "eLoyalty Scheduler Service Executing!";
jobDetail.JobDataMap["myStateData"] = new ArrayList();
// fire every minute
Trigger trigger = TriggerUtils.MakeMinutelyTrigger();
// start on the next even minute
trigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow);
// name it
trigger.Name = "NextEvenMinute";
// schedule it
sched.ScheduleJob(jobDetail, trigger);
// start the schedule
sched.Start();
eventLog.WriteEntry("--- STARTED eLoyalty Scheduler Service ---");
}
My Job's Execute() function is as follows:
public void Execute(JobExecutionContext context)
{
try
{
string instName = context.JobDetail.Name;
string instGroup = context.JobDetail.Group;
JobDataMap dataMap = context.MergedJobDataMap;
string jobSays = dataMap.GetString("jobSays");
ArrayList state = (ArrayList)dataMap["myStateData"];
state.Add(DateTime.UtcNow);
Console.WriteLine("Instance {0} of PortalSchedulerJob says: {1} @ {2}", instName, jobSays, DateTime.UtcNow);
Console.ReadKey();
}
catch (JobExecutionException Ex)
{
throw Ex;
}
}
If you can help me figure out how to troubleshoot my ACTUAL schedule activity, I may be able to solve this on my own… ?
Best Answer
In Quartz.NET tasks, you must only raise JobExecutionException exceptions: Quartz.net- Lesson 3:
Instead of:
Do something like this:
You can then handle the Exception centrally: