Ejemplo n.º 1
0
        public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobExecutionException, CancellationToken cancellationToken)
        {
            if (jobExecutionException != null)
            {
                return(Task.CompletedTask);
            }

            if (context == null)
            {
                throw new ArgumentNullException();
            }

            Console.Out.WriteAsync("JobComplete at " + DateTime.Now.ToLongTimeString());

            ISimpleTrigger s = (ISimpleTrigger)context.Trigger;

            var finishedJob = context.JobDetail;

            if (s.TimesTriggered == s.RepeatCount)
            {
                context.Scheduler.DeleteJob(finishedJob.Key);
                AlarmRouteRule rule        = (AlarmRouteRule)finishedJob.JobDataMap.Get("rule");
                IJobDetail     nextJob     = (IJobDetail)finishedJob.JobDataMap.Get("nextJob");
                ITrigger       nextTrigger = (ITrigger)finishedJob.JobDataMap.Get("nextTrigger");

                if (nextJob == null)
                {
                    return(Task.CompletedTask);
                }
                ITrigger tr = nextTrigger.GetTriggerBuilder().StartAt(DateTime.Now.AddSeconds(rule.Duration)).Build();
                context.Scheduler.ScheduleJob(nextJob, tr);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
            public async Task Execute(IJobExecutionContext context)
            {
                JobDataMap     jobDataMap = context.MergedJobDataMap;
                AlarmRouteRule rule       = (AlarmRouteRule)jobDataMap.Get("rule");
                Alarm          alarm      = (Alarm)jobDataMap.Get("alarm");

                Console.WriteLine(String.Format("Alarm {0} given assignment for destination {1} with duration {2} and repeat {3}", alarm.NimId, rule.Destination, rule.Duration, rule.Repeat));
                await Console.Out.WriteLineAsync(String.Format("Alarm {0} given update and sent to queue for processing (await) - time is: {1}", alarm.NimId, DateTime.Now.ToLongTimeString()));
            }
Ejemplo n.º 3
0
        private static ITrigger GetTrigger(string group, AlarmRouteRule rule, IJobDetail job)
        {
            ITrigger trigger = null;


            trigger = TriggerBuilder.Create()
                      .WithIdentity("Trigger_route_rule" + rule.Id, group)
                      .WithSimpleSchedule(x => x
                                          .WithIntervalInMinutes(rule.Duration)
                                          .WithRepeatCount(rule.Repeat))
                      .ForJob(job)
                      .Build();



            return(trigger);
        }