Exemplo n.º 1
0
        public override void UnscheduleJob(string jobName, string jobGroup)
        {
            if (!string.IsNullOrEmpty(jobName) && !string.IsNullOrEmpty(jobGroup))
            {
                var details = _quartzScheduler.GetJobDetail(jobName, jobGroup);

                if (details != null)
                {
                    _quartzScheduler.DeleteJob(details.Key);

                    OnJobUnscheduled(JobInfo.Create(jobGroup, jobName));
                }
            }
        }
Exemplo n.º 2
0
        private void AddJob(JobInfo addinfo)
        {
            if (addinfo == null)
            {
                return;
            }
            JobInfo newinfo = addinfo.Create();

            if (newinfo == null)
            {
                return;
            }
            newinfo.onJobInfoChanged += onJobInfoChanged;
            this.WatchConfigFrm(newinfo);
        }
Exemplo n.º 3
0
        public override void UnscheduleJob(BaseJob scheduleJob)
        {
            var metadata = Metadata.ExtractData(scheduleJob);

            if (metadata != null)
            {
                var details = _quartzScheduler.GetJobDetail(metadata.Name, metadata.Group);

                if (details != null)
                {
                    _quartzScheduler.DeleteJob(details.Key);

                    OnJobUnscheduled(JobInfo.Create(metadata.Group, metadata.Name));
                }
            }
        }
Exemplo n.º 4
0
        public override void PauseJob(string jobName, string jobGroup)
        {
            if (!string.IsNullOrEmpty(jobName) && !string.IsNullOrEmpty(jobGroup))
            {
                var details = _quartzScheduler.GetJobDetail(jobName, jobGroup);

                if (details != null)
                {
                    _quartzScheduler.PauseJob(details.Key);

                    OnJobPaused(JobInfo.Create(jobGroup, jobName,
                                               state: JobState.Paused.ToString(),
                                               isNextFireTimeSpecified: true
                                               ));
                }
            }
        }
Exemplo n.º 5
0
        public override void ScheduleJob(BaseJob scheduleJob)
        {
            var metadata = Metadata.ExtractData(scheduleJob);

            var jobKey = new JobKey(metadata.Name, metadata.Group);

            if (_quartzScheduler.CheckExists(jobKey).Result)
            {
                // if the job already scheduled, we don't want to re-schedule it
                return;
            }

            var job = JobBuilder.Create <QuartzJob>()
                      .WithIdentity(metadata.Name, metadata.Group)
                      .WithDescription(metadata.Description)
                      .UsingJobData("TypeFullName", metadata.Type.FullName)
                      .Build();

            var trigger = TriggerBuilder.Create()
                          .WithIdentity($"{metadata.Name}Trigger", metadata.Group)
                          .StartNow()
                          .WithCronSchedule(metadata.Schedule, trg => trg
                                            .WithMisfireHandlingInstructionDoNothing())
                          .ForJob(metadata.Name, metadata.Group)
                          .Build();

            _quartzScheduler.ScheduleJob(job, trigger);

            OnJobScheduled(JobInfo.Create(metadata.Group, metadata.Name,
                                          logger: scheduleJob.GetLogger(),
                                          scheduleExp: metadata.Schedule,
                                          schedule: CronExpressionDescriptor.ExpressionDescriptor.GetDescription(metadata.Schedule, new Options()
            {
                Locale = "en"
            }),
                                          nextFire: trigger.GetNextFireTimeUtc()
                                          ));

            // TODO: Find better way to schedule paused job
            if (metadata.State == (byte)JobState.Paused)
            {
                PauseJob(metadata.Name, metadata.Group);
            }
        }
Exemplo n.º 6
0
        public override void ResumeJob(string jobName, string jobGroup)
        {
            if (!string.IsNullOrEmpty(jobName) && !string.IsNullOrEmpty(jobGroup))
            {
                var details = _quartzScheduler.GetJobDetail(jobName, jobGroup);

                if (details != null)
                {
                    _quartzScheduler.ResumeJob(details.Key);

                    var triggers = _quartzScheduler.GetTriggersOfJob(details.Key);

                    OnJobResumed(JobInfo.Create(jobGroup, jobName,
                                                state: JobState.Normal.ToString(),
                                                nextFire: triggers.Result.SingleOrDefault()?.GetNextFireTimeUtc()
                                                ));
                }
            }
        }
Exemplo n.º 7
0
        private JobInfo ExtractJobInfo(string name, string group, IJobDetail jobDetail, ITrigger trigger)
        {
            var jobInfo = JobDetailService.GetJobDetail(name, group);

            var scheduleExpr = string.Empty;

            if (trigger is ICronTrigger cronTrigger)
            {
                scheduleExpr = cronTrigger.CronExpressionString;
            }

            var originJobInfo = JobInfo.Create(
                group, name,
                desc: jobDetail.Description,
                schedule: scheduleExpr,
                state: _quartzScheduler.GetTriggerState(trigger.Key).Result.GetJobState().ToString(),
                actionState: (_quartzScheduler.GetCurrentlyExecutingJobs().Result.ContainsJob(name, group))
                    ? JobActionState.Executing.ToString()
                    : string.Empty,
                nextFire: trigger.GetNextFireTimeUtc(),
                prevFire: trigger.GetPreviousFireTimeUtc()
                );

            return(JobInfo.Create(
                       group, name,
                       desc: jobInfo?.JobDescription ?? originJobInfo.Description,
                       schedule: CronExpressionDescriptor.ExpressionDescriptor.GetDescription(
                           jobInfo?.JobSchedule ?? originJobInfo.Schedule, new Options {
                Locale = "en"
            }),
                       state: originJobInfo.State,
                       actionState: originJobInfo.ActionState,
                       nextFire: jobInfo?.JobNextRunTime ?? originJobInfo.NextFireTimeUtc,
                       prevFire: jobInfo?.JobLastRunTime ?? originJobInfo.PrevFireTimeUtc
                       ));
        }