How to get JobKey / JobDetail of Quartz Job

天涯浪子 提交于 2019-12-01 09:04:06

You can just create a new job key (which is just a fancy storage for a job name and a group name)

new JobKey("jobName", "jobGroupName");

As long as your job name and job group name is the same with which you created your job, you will be able to get your job detail.

var jobDetail = quartzScheduler.GetJobDetail(new JobKey("jobName", "jobGroupName"));

personnally, i implement a static method in my job class to centralise the job key creation so i don't have many litterals all over the place :

public static JobKey GetJobKey(EntityServer server)
{
    return new JobKey("AutoRestart" + server.Id, "AutoRestart");
}

Note that it is also true for the triggerKey

public static TriggerKey GetTriggerKey(EntityServer server)
{
    return new TriggerKey("AutoRestart" + server.Id, "AutoRestart");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!