locked
TopShelf Quartz error message when running in production RRS feed

  • Question

  • User-1188570427 posted

    I am seeing this error message:

    Error Message in JobScheduler.Start(): Quartz.ObjectAlreadyExistsException: Unable to store Trigger: 'group1.trigger1', because one already exists with this identification.
    at Quartz.Simpl.RAMJobStore.StoreTrigger(IOperableTrigger newTrigger, Boolean replaceExisting)
    at Quartz.Simpl.RAMJobStore.StoreJobAndTrigger(IJobDetail newJob, IOperableTrigger newTrigger)
    at Quartz.Core.QuartzScheduler.ScheduleJob(IJobDetail jobDetail, ITrigger trigger)
    at Quartz.Impl.StdScheduler.ScheduleJob(IJobDetail jobDetail, ITrigger trigger)
    at TextSvc.ScheduledTask.JobScheduler.Start(TextSvcSessionDto textSvcSession) | 9/7/2018 10:10:15 PM

    I am checking if the trigger exist, but it is still failing on production.

    Here is my code:

     scheduler = StdSchedulerFactory.GetDefaultScheduler();
    
                        job = JobBuilder.Create<MyJob>().Build();
    
                        JobKey jobKey = new JobKey("group1", "trigger1");
    
                        if (scheduler.CheckExists(jobKey) == true)
                        {
                            scheduler.DeleteJob(jobKey);
    
                            #region 'Logging Info/Error'
    
                            try
                            {
                                
                                // Log to db that I deleted the Job...
                            }
                            catch
                            {
                                // if error occurs... keep going...
                            }
    
                            #endregion 'Logging Info/Error'
                        }
    
    
    
                        trigger = TriggerBuilder.Create()
                                .WithIdentity("trigger1", "group1")
                                .StartNow()
                                .WithSimpleSchedule(x => x
                                    .WithIntervalInSeconds(GlobalParamInfo.TextSvcScheduleTaskIntervalInSecondsNbr)
                                    .RepeatForever())
                                .Build();
    
    

    Any ideas?

    Friday, September 7, 2018 10:13 PM

All replies

  • User-943250815 posted

    Just a guess, try to use a TriggerKey instead of instead of Name and group

    TriggerKey zTriggerKey = new TriggerKey("trigger1", "group1");
    trigger = TriggerBuilder.Create()
                                .WithIdentity(zTriggerKey)
                                .StartNow()
                                .WithSimpleSchedule(x => x
                                    .WithIntervalInSeconds(GlobalParamInfo.TextSvcScheduleTaskIntervalInSecondsNbr)
                                    .RepeatForever())
                                .Build();

    You can also, loop through Jobs and Triggers to inspect some more info

    {
        IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
        foreach (string JobGroup in scheduler.GetJobGroupNames)
        {
            foreach (var JobKey in scheduler.GetJobKeys(Matchers.GroupMatcher<JobKey>.GroupEquals(JobGroup)))
            {
                foreach (var Trigger in scheduler.GetTriggersOfJob(JobKey))
                {
                    string tJobKeyName = Trigger.JobKey.Name;
                    string tJobKeyGroup = Trigger.JobKey.Group;
                    string tSince = scheduler.GetMetaData.RunningSince.Value.DateTime.ToLocalTime.ToString("yyyy-MM-dd@HH:mm:ss");
                    string tNext = Trigger.StartTimeUtc.ToString["yyyy-MM-dd@HH:mm:ss"];
    // or any other action } } } }

    I would suggest you implement Listeners, they can help you detect lots of actions in Quartz Scheduler

    https://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/trigger-and-job-listeners.html
    https://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/scheduler-listeners.html

    Saturday, September 8, 2018 2:45 PM