I have created a scheduler that runs every 10 minutes to check a table and if any data exists in that table then it sends emails to those persons accordingly. I am using Visual Studio 2010. I installed Quartz and added it in my bin and references also. It is working perfectly in my local and in my testing environment also. I added some logs just to make sure the scheduler is triggering and it inserts data into my table after every 10 minutes.
Now I deployed it on the client environment and the scheduler is not getting trigerred at all. I searched some other questions and it said to add TimeZone in my scheduler but this does not work also.
here is my code
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<EmailTrigger>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInMinutes(10)
.OnEveryDay()
.InTimeZone(TimeZoneInfo.Local) //added later
)
.Build();
scheduler.ScheduleJob(job, trigger);
}
And EmailTrigger.cs
public void Execute(IJobExecutionContext context)
{
try
{
clsEmail objEmail = new clsEmail();
if (dtLayer.getValueFromStaticConfiguration("EmailTriggerOnApproval", "N") == "Y")
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values ('Trigger started 1','Trigger started 1' , GetDate())");
DataTable dtData = dtLayer.getDataTableFromQuery("select * from EmailSendData where IsSend is null");
if (dtData.Rows.Count > 0)
{
for (int i = 0; i < dtData.Rows.Count; i++)
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values ('Trigger started 2','Trigger started 2' , GetDate())");
string NomineeList = dtData.Rows[i]["NomineeUser"].ToString();
string FromEmpid = dtData.Rows[i]["FromEmpID"].ToString();
string EmailID = dtData.Rows[i]["EmailID"].ToString();
string url = dtData.Rows[i]["URL"].ToString();
string Type = dtData.Rows[i]["Type"].ToString();
string query = dtData.Rows[i]["EmailDetails"].ToString();
string UserID = dtData.Rows[i]["UserID"].ToString();
string NotificationID = dtData.Rows[i]["NotificationID"].ToString();
string CCMail = dtData.Rows[i]["CCMail"].ToString();
string ApprovalCode = dtData.Rows[i]["ApprovalCode"].ToString();
string Id = dtData.Rows[i]["ID"].ToString();
DataTable dtEmailDetails = dtLayer.getDataTableFromQuery(query);
ArrayList emailDetails = dtLayer.datatableTOarraylist(dtEmailDetails);
emailDetails.Add(ApprovalCode);
if (dtLayer.getValueFromStaticConfiguration("SendEmail", "N") == "Y")
objEmail.sendMailNewFunction(NomineeList, FromEmpid, EmailID, url, Type, "", emailDetails, UserID, false, null, NotificationID, CCMail);
dtLayer.execute("update EmailSendData set isSend='Y' where ID= " + Id + " ");
}
}
else
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values ('Job ran successfully','No approved cases pending' , GetDate())");
}
}
}
catch (Exception e)
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values (" + dtLayer.checkNull(e.ToString()) + ",'Exception Catch',GetDate())");
throw e;
}
}
JobScheduler.Start(); This function is already there in my global.asax.cs which starts the scheduler
I don't know why my JobScheduler is not getting trigerred. Any suggestions please?
I have deployed the updated patch two times and also restarted the IIS Server. Nothing worked .
Anyone can help me? Nothing has worked till now.