1

I am currently investigating using Quartz.NET for scheduling tasks in my system. As an example of how I am using Quartz.NET, below is a very simple example demonstrating how I am scheduling a task:

class Program
{
    static void Main(string[] args)
    {
        var properties = new NameValueCollection();
        properties["quartz.scheduler.instanceName"] = "TestScheduler";
        properties["quartz.scheduler.instanceId"] = "instance_one";
        properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
        properties["quartz.jobStore.useProperties"] = "true";
        properties["quartz.jobStore.dataSource"] = "default";
        properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
        properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
        properties["quartz.dataSource.default.connectionString"] = "Server=.\\SqlExpress;Database=quartz;Trusted_Connection=True;";
        properties["quartz.dataSource.default.provider"] = "SqlServer-20";

        var scheduler = new StdSchedulerFactory(properties).GetScheduler();

        scheduler.Start();

        TriggerSimpleJob(scheduler);

        Console.WriteLine("Waiting For Job");
        Console.ReadLine();
    }

    private static void TriggerSimpleJob(IScheduler scheduler)
    {
        ITrigger trigger = TriggerBuilder.Create()
                              .WithIdentity("trigger1", "group1")
                              .StartAt(DateBuilder.EvenSecondDateAfterNow())
                              .UsingJobData("myTriggerParameter", "myTriggerValue")
                              .UsingJobData("myParameter", "triggerParameter")
                              .Build();

        IJobDetail jobDetail = JobBuilder.Create<SimpleJob>().WithIdentity("job1", "group1")
            .UsingJobData("myParameter", "myValue")
            .Build();

        scheduler.ScheduleJob(jobDetail, trigger);
    }
}

public class SimpleJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
       Console.WriteLine("Job completed");
    }
}

The question I have is this:

I would like to decouple of the scheduling of jobs from the execution of jobs.

In the above example, after the job has been scheduled, if the process is still running when the scheduled time arrives the job is executing within this process. Ideally I would like to be able to have a dedicated server with an instance of the Quartz.NET scheduler running that is dedicated to executing jobs, and be able to schedule jobs from other processes knowing the job will be executed on this dedicated server.

I have tried simply setting the property "quartz.threadPool.threadCount" to "0" on the process that schedules jobs, but this throws an exception. Is there any configuration properties on the scheduler that will achieve what I am trying to do?

Lawrence
  • 3,287
  • 19
  • 32

2 Answers2

1

Good morning,

you can read my answer here.

What I would suggest is to use ADO.NET Job Store (and it seems you're using it). The application in charge of scheduling jobs should be configured setting the property threadPool to ZeroSizeThreadPool:

properties["quartz.threadPool.type"] = "Quartz.Simpl.ZeroSizeThreadPool, Quartz";

You can read more about this type of thread-pool here.

the application in charge of the execution of the jobs should be configured with these settings:

properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "10";
properties["quartz.threadPool.threadPriority"] = "Normal";
Community
  • 1
  • 1
LeftyX
  • 35,328
  • 21
  • 132
  • 193
0

Remove the line

 scheduler.Start();
sgmoore
  • 15,694
  • 5
  • 43
  • 67