asp.net - Configuring Quartz.Net to stop a job from executing, if it is taking longer than specified time span -
i working on making scheduler, windows scheduler using quartz.net.
in windows scheduler, there option stop task running if takes more specified time. have implement same in scheduler.
but not able find extension method/setting configure trigger or job accordingly.
i request inputs or suggestions it.
you can write small code set custom timout running on thread. implement iinterruptablejob interface , make call interrupt() method thread when job should interrupted. can modify following sample code per need. please make necessary checks/config inputs wherever required.
public class mycustomjob : iinterruptablejob { private thread runner; public void execute(ijobexecutioncontext context) { int timeoutinminutes = 20; //read config or db. timespan timeout = timespan.fromminutes(timeoutinminutes); //run job here. //as job needs interrupted, let create new task that. var task = new task(() => { thread.sleep(timeout); interrupt(); }); task.start(); runner = new thread(performscheduledwork); runner.start(); } private void performscheduledwork() { //do wish in schedled task. } public void interrupt() { try { runner.abort(); } catch (exception) { //log it! } { //do wish clean task. } } }
Comments
Post a Comment