none
Using quartz 3.0.5.0 on Windows form application and having an issue where cannot find the existing triggers

    Pertanyaan

    • created quartzUse instance in the another class where I am calling UpdateSchedules method when button(Add or delete or updated) is pressed
    • after creating a first job and trigger for the first timer
    • creating another one after adding another trigger key with start and end time and added in List Jobs and calling UpdateSchedules method
    namespace CustomSchedules
    {
        public class QuartzUse
        {
    
            public delegate void EventTriggered(JobModel sender);
    
            public event EventTriggered QuartzEvent;
            public List<JobModel> Jobs = new List<JobModel>();
    
            private void SetEvent(JobModel job)
            {
                if (job != null)
                    QuartzEvent(job);
            }
    
       
            public async Task UpdateSchedules()
            {
    
                NameValueCollection props = new NameValueCollection
                    {
                        { "quartz.serializer.type", "binary" }
                    };
                ISchedulerFactory factory = new StdSchedulerFactory(props);
                IScheduler scheduler = await factory.GetScheduler();
                scheduler.Context.Put("context", this);
    
                   if (!scheduler.IsStarted)
                    await scheduler.Start();
    
    
                foreach (var info in Jobs)
                {
                    var jobDataMap = new Dictionary<string, object>();
                    jobDataMap.Add("job", info);
    
                    var triggerKey = new TriggerKey(info.TriggerName, "group1");
                    var existingJob = await scheduler.GetTrigger(triggerKey);
    
    
    
                    if (existingJob == null)
                    {
                        IJobDetail job = JobBuilder.Create<SomeJob>()
                       .WithIdentity("job" + info.TriggerName, "group1")
                       .UsingJobData("jobdata", JsonConvert.SerializeObject(info))
                       .Build();
    
                        ITrigger trigger = TriggerBuilder.Create()
                                .WithIdentity("trigger" + info.TriggerName, "group1")
                                .StartAt(info.StartTime)
                                .EndAt(info.EndTime)
                                .Build();
                        await scheduler.ScheduleJob(job, trigger);
    
                    }
                    else if(existingJob!=null && info.state==0)
                    {
                        await scheduler.UnscheduleJob(triggerKey);
                    }
                    else
                    {
                        IJobDetail job = JobBuilder.Create<SomeJob>()
                       .WithIdentity("job" + info.TriggerName, "group1")
                       .UsingJobData("jobdata", JsonConvert.SerializeObject(info))
                       .Build();
    
                        ITrigger trigger = TriggerBuilder.Create()
                                .WithIdentity("trigger" + info.TriggerName, "group1")
                                .StartAt(info.StartTime)
                                .EndAt(info.EndTime)
                                .Build();
                        await scheduler.RescheduleJob(triggerKey, trigger);
                    }
                existingJob = await scheduler.GetTrigger(triggerKey);
    
                var jobKey = new JobKey("job"+triggername, "group1");
                var ja = scheduler.CheckExists(jobKey);
                }
    
                // and last shut down the scheduler when you are ready to close your program
    
            }
    
            public class SomeJob : IJob
            {
                public async Task Execute(IJobExecutionContext context)
                {
                    var jobDetail = context.JobDetail as JobDetailImpl;
                    var jobDataMap = JsonConvert.DeserializeObject<JobModel>(jobDetail.JobDataMap.GetString("jobdata"));
                    var schedulerContext = context.Scheduler.Context.Get("context");
    
                    if (schedulerContext != null)
                    {
                        var quartzObject = schedulerContext as QuartzUse;
                        quartzObject.SetEvent(jobDataMap);
                    }
    
                    //await Console.Out.WriteLineAsync(jobDetail.Name + " got triggered");
                }
            }
    
        }
    }

    But for some reason cannot find the existing trigger to reschedule it I am newbie in C#


    • Dipindahkan oleh CoolDadTx Senin, 02 Juli 2018 13.45 Third party product
    Senin, 02 Juli 2018 08.14

Semua Balasan

  • This forum is for C#-specific questions only. Your question appears to be related to a third party product. Please post your question related to these products in their forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Senin, 02 Juli 2018 13.45
  • forgive me although i am using third party library but the issue i suspect is more of c# basics that i am missing that's why i posted it here
    • Diedit oleh Sahil1923 Senin, 02 Juli 2018 23.29
    Senin, 02 Juli 2018 23.28