How do I reload all jobs and schedules in Quartz.Net periodically?

Viewed 2521

I am using Quartz.net within a Windows service to schedule jobs that exist within my database.

My users have will have a front end to this table whereby they can change the CRON expression. Currently, my application doesn't have any logic to change the CRON expression or add/delete jobs without having the service restarted (as this will trigger the reload of jobs). I am using the below code to load all the jobs from my database.

protected void LoadJobs()
{
    logger.Info("Loading jobs.");
    var jobs = middlewareRepository.GeActiveJobs();

    foreach (var job in jobs)
    {
        IJobDetail jobDetail = JobBuilder.Create<JobDespatcher>()
            .WithIdentity(job.Description)
            .UsingJobData("JobId", job.Id)
            .Build();

        ITrigger trigger = TriggerBuilder.Create()
            .WithCronSchedule(job.CronExpression)
            .Build();

        scheduler.ScheduleJob(jobDetail, trigger);
        logger.InfoFormat("Job with id {0} ({1}) has been scheduled.", job.Id, job.Description);
    }
}

How would I go about clearing the scheduler queue and reloading the jobs.. say by checking every hour? Does Quartz.Net have a built in function to do this? Or would I have to build some logic that would unload all jobs/schedules and reload them? If I remove a job that is currently running, will that job be stopped or will it continue?

Any advice on the best way to implement this would be great.

2 Answers
Related