I am new to MSMQ, Quartz, and services. I have a service that will send a notification email if an exception is thrown. I am trying to find a way to pause or stop the service once an email is sent so I don't receive the same exception email over and over again. I only need the email once. So far I have tried:
- _scheduler.DeleteJob(jobKey);
- _scheduler.UnscheduleJob(triggerKey);
- _scheduler.Shutdown();
- _scheduler.Interrupt(jobKey);
- serviceController.Stop();
- serviceController.Pause();
- _scheduler.RescheduleJob(key, exceptionTrigger); <- over ride my old trigger with a new one that has an interval time of zero
My job and trigger code work as expected:
public void CreateRegistration()
{
this._scheduler = StdSchedulerFactory.GetDefaultScheduler();
CreateJob();
CreateTrigger();
RegisterWithScheduler();
}
public void CreateJob()
{
_scheduler.Start();
this._job = JobBuilder.Create<RecieveMessageJob>()
.WithIdentity("ReceiveMessagesJob",
this._messageGroupName)
.Build();
}
public void CreateTrigger()
{
_trigger = TriggerBuilder.Create()
.WithIdentity(this._triggerName, this._messageGroupName)
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInMinutes(1)
.RepeatForever())
.Build();
}
public void RegisterWithScheduler()
{
_scheduler.ScheduleJob(_job, _trigger);
}
In my ReceiveMessageJob job class I look for exception errors in my execute method (Execute(IJobExecutionContext context)) and call PauseService() if need be. Here you can see all my various attempts to stop or pause my service.
public void PauseService()
{
TriggerKey triggerKey = this._trigger.Key;
JobKey jobKey = this._job.Key;
// Define a new Trigger
//ITrigger exceptionTrigger = TriggerBuilder.Create()
// .WithIdentity("exceptionTrigger", this._messageGroupName)
// .StartNow()
// .WithSimpleSchedule(x => x
// .WithIntervalInMinutes(0))
// .Build();
// tell the scheduler to remove the old trigger with the given key, and put the new one in its place
//_scheduler.RescheduleJob(key, exceptionTrigger);
//_scheduler.DeleteJob(jobKey);
//_scheduler.UnscheduleJob(triggerKey);
//_scheduler.Shutdown();
//_scheduler.Interrupt(jobKey);
//ServiceController serviceController = new ServiceController("MessagingService");
//serviceController.Stop();
//serviceController.Pause();
}
I can't figure out why none of my attempts have worked. Does anyone see something wrong in my code or know of a different way? Thanks in advance!