[英]Quartz.net job not firing
我已經使用Quartz.net設置了cron作業,但是它似乎沒有啟動。
上傳后,我對web.config進行了更改以重新啟動應用程序,因此它應運行Application_Start方法。 我還使用一個簡單的觸發器測試了Job,並且工作正常,所以我不確定發生了什么。
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof(Recorder));
jobDetail.JobDataMap["domain"] = "www.mydomain.com";
jobDetail.JobDataMap["userId"] = "2";
// Create trigger (everything is in UTC!!!)
CronTrigger cronTrigger = new CronTrigger("Schedule");
cronTrigger.StartTimeUtc = TriggerUtils.GetEvenSecondDate(DateTime.UtcNow);
cronTrigger.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); // run in pacific timezone
cronTrigger.CronExpressionString = "0 30 13 ? * MON-FRI *";
sched.ScheduleJob(jobDetail, cronTrigger);
}
public class Recorder : IJob
{
public void Execute(JobExecutionContext context)
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
string domain = dataMap.GetString("domain");
string userId = dataMap.GetString("userId");
string url = "http://" + domain + "/record.aspx?userId=" + userId;
using (WebClient client = new WebClient())
{
client.DownloadString(url);
}
}
}
您尚未啟動調度程序:
sched.Start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.