Long-running jobs and Scheduler events

801 views
Skip to first unread message

Jochen Jonckheere

unread,
Sep 20, 2011, 7:09:18 AM9/20/11
to quar...@googlegroups.com
Is there a way to notify a job that the scheduler has been shutdown, paused or resumed?

In my case I have Jobs that can run for a long time, for example process thousands of files in a folder. But when the Scheduler gets stopped or paused, the job should be notified and stop after the current file.

Jason Meckley

unread,
Sep 20, 2011, 12:29:00 PM9/20/11
to quar...@googlegroups.com
I thought the scheduler handled the pausing/stopping of jobs if the scheduler itself was stopped. For your situation I would consider narrowing the scope of the job and scheduling more jobs. the process as a whole would still be long running, but each job instance is a small part of the process. This way the scheduler could "remember" where it left off. when the scheduler is stopped allow the current running jobs to finish and do not start any new jobs.

you will probably need a way to aggregate the results of the smaller jobs. This could probably be accomplished using a job listners and some form of persistent storage.

Penner, Matthew

unread,
Sep 20, 2011, 1:43:41 PM9/20/11
to quar...@googlegroups.com

Is there no “schedule” listener or callback member in the IJob interface itself that the scheduler can use to notify the job that it is shutting down?  I’m just starting to work with Quartz and I don’t know what the Java framework has, but I know that most threading frameworks have some mechanism to tell the thread that it is being suspended or shut down.

 

For instance, the PLINQ framework has a BackgroundWorker.WorkerSupportsCancellation flag that if you set to true it will update a BackgroundWorker.CancellationPending flag that you can monitor in your loop and act accordingly.  Of course there is always the classic strategy like the ASP.Net Application_End method you can override as well.

 

I would think an addition like this to Quartz, even if it is a branch from the Java version, would be really useful.  It would allow you to properly save state if necessary.

 

Matt Penner
Network Engineer II

Val Verde Unified School District

mpe...@valverde.edu
(951) 940-6100 x10709

--
You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To view this discussion on the web visit https://groups.google.com/d/msg/quartznet/-/Ptgmcz-9kCMJ.
To post to this group, send email to quar...@googlegroups.com.
To unsubscribe from this group, send email to quartznet+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/quartznet?hl=en.

Marko Lahma

unread,
Sep 20, 2011, 2:45:34 PM9/20/11
to quar...@googlegroups.com
There's IInterruptableJob interface that is quite close to your
requirements I believe:

http://quartznet.sourceforge.net/apidoc/topic15.html

-Marko

Penner, Matthew

unread,
Sep 20, 2011, 5:33:54 PM9/20/11
to quar...@googlegroups.com
Perfect! :) I thought there had to be something. I will definitely make use of this.

Matt Penner
Network Engineer II
Val Verde Unified School District
mpe...@valverde.edu
(951) 940-6100 x10709

Jochen Jonckheere

unread,
Sep 21, 2011, 5:32:51 AM9/21/11
to quar...@googlegroups.com
Thanks, I created an extension method on Scheduler to interrupt all CurrentlyExecutingJobs, and I call it just before ShutDown and PauseAll.

    [CLSCompliant(false)]
    public static class SchedulerExtension
    {
        public static void InterruptCurrentlyExecutingJobs(this IScheduler scheduler)
        {
            foreach (var result in scheduler.GetCurrentlyExecutingJobs().Cast<JobExecutionContext>().Select(je => je.JobInstance).OfType<IInterruptableJob>())
            {
                result.Interrupt();
            }
        }
    }

Jason Meckley

unread,
Sep 21, 2011, 10:20:40 AM9/21/11
to quar...@googlegroups.com
you may want to filter out jobs that do not inherit IInterruptableJob.
scheduler
     .GetCurrentlyExecutingJobs()
     .Select(context => context.JobInstance)
     .Select(job => job as IInterruptableJob)
     .Where(job => job != null)
     .Each(job => job.Interrupt());
Reply all
Reply to author
Forward
0 new messages