2

I'm using Quartz.Net scheduler to schedule my jobs. I'm using ADOJOBSTORE to store all these values.

Couldn't store job: Unable to store Job: 'job6', because one already exists with this identification When I try to run it throwing the above error. Any idea?

        ILog log = LogManager.GetLogger(typeof(CronTrigger));

        log.Info("------- Initializing -------------------");

        // First we must get a reference to a scheduler
        ISchedulerFactory sf = new StdSchedulerFactory();
        IScheduler sched = sf.GetScheduler();

        log.Info("------- Initialization Complete --------");

        log.Info("------- Scheduling Jobs ----------------");

        // jobs can be scheduled before sched.start() has been called



        // job 6 will run every 30 seconds but only on Weekdays (Monday through Friday)
        IJobDetail job = JobBuilder.Create<SimpleJob>()
            .WithIdentity("job6", "group1")
            .Build();

        ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
                                     .WithIdentity("trigger6", "group1")
                                     .WithCronSchedule("0,30 * * ? * MON-FRI")
                                     .Build();

        DateTimeOffset ft = sched.ScheduleJob(job, trigger);
        log.Info(job.Key + " has been scheduled to run at: " + ft
                 + " and repeat based on expression: "
                 + trigger.CronExpressionString);


        log.Info("------- Starting Scheduler ----------------");

        // All of the jobs have been added to the scheduler, but none of the
        // jobs
        // will run until the scheduler has been started
        sched.Start();

        log.Info("------- Started Scheduler -----------------");

        //log.Info("------- Waiting five minutes... ------------");
        //try
        //{
        //    // wait five minutes to show jobs
        //    Thread.Sleep(300 * 1000);
        //    // executing...
        //}
        //catch (ThreadInterruptedException)
        //{
        //}

        //log.Info("------- Shutting Down ---------------------");

        //sched.Shutdown(true);

        //log.Info("------- Shutdown Complete -----------------");

        SchedulerMetaData metaData = sched.GetMetaData();
        log.Info(string.Format("Executed {0} jobs.", metaData.NumberOfJobsExecuted));

Here are my app.config settings

<add key="quartz.scheduler.instanceId" value="AUTO"/>
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="2"/>

<add key="quartz.jobStore.misfireThreshold" value="60000"/>


<add key="quartz.jobStore.clustered" value="true"/>
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/>
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.dataSource" value="myDS"/>

<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz"/>
<!-- i have modifed for this post -->
<add key="quartz.dataSource.myDS.connectionString" value="Server=mydatabaseconnectionstring goes here;Trusted_Connection=False;Encrypt=True;"/>

<add key="quartz.dataSource.myDS.provider" value="SqlServer-20"/>
<add key="quartz.jobStore.useProperties" value="true"/>

Can I do some thing like this... Before adding the job or trigger Check for the record from the database and if not exists add the job?. Is it ok to do this?

- or - is it easier to implement Azure Queues to schedule my jobs? Thanks!!

user1418168
  • 91
  • 1
  • 1
  • 10
  • Can I do some thing like this... Before adding the job or trigger Check for the record from the database and if not exists add the job?. Is it ok to do this? – user1418168 Jun 25 '12 at 17:14

1 Answers1

2

This is because ScheduleJob will try add the job every time. You should either use AddJob with overload specifying whether to overwrite existing or just add the job once (check for existence) and then add new triggers when needed.

When using AdoJobStore the trigger and jobs will be there on the second run as they are persisted. In your case you have propably already ran the code once and thus the job exists the persistent job store. With RamJobStore it would naturally be a different thing.

Marko Lahma
  • 6,586
  • 25
  • 29
  • I was looking for some example and couldn't find any. Any samples or links related to this will be helpful... – user1418168 Jun 24 '12 at 02:15
  • ScheduleOneTimeJob sample from another blog, but still I'm not clear on how to implement this...Any inputs? Thanks!!! – user1418168 Jun 24 '12 at 03:24
  • I've tried to do AddJob(job, false); Then it throwed an error saying the job must be durable. In the job creation I've added Durable. After that When I tried to run the program , it won't respond, I had to do a reboot of the machine. Any ideas why this is happening? – user1418168 Jun 24 '12 at 21:11
  • Hi, Its very critical and time sensitive to know how to implement this. Any help is greatly appreciated!!!!! Thanks in Advance!! – user1418168 Jun 25 '12 at 00:14