| | |
| | | WebResponseContent result = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (_scheduler.IsShutdown && _scheduler.IsStarted) |
| | | if (_scheduler.IsShutdown || !_scheduler.IsStarted) |
| | | { |
| | | // 从Factory中获取Scheduler实例 |
| | | NameValueCollection collection = new NameValueCollection |
| | |
| | | } |
| | | else |
| | | { |
| | | await _scheduler.Shutdown(); |
| | | // 调度器已在运行,直接返回提示 |
| | | result = WebResponseContent.Instance.Error(QuartzJobInfoMessage.JobHasStart); |
| | | return result; |
| | | } |
| | |
| | | //等待任务运行完成 |
| | | await _scheduler.Shutdown(false); |
| | | |
| | | await Console.Out.WriteLineAsync(QuartzJobInfoMessage.StopJobSuccess); |
| | | QuartzLogger.Info(QuartzJobInfoMessage.StopJobSuccess); |
| | | result = WebResponseContent.Instance.OK(QuartzJobInfoMessage.StopJobSuccess); |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | IReadOnlyCollection<string> jobGroupNames = await _scheduler.GetJobGroupNames(); |
| | | |
| | | await _scheduler.PauseAll(); |
| | | |
| | | // 调度器已停止,直接返回提示(不再对已 shutdown 的 scheduler 调用 PauseAll) |
| | | result = WebResponseContent.Instance.Error(QuartzJobInfoMessage.JobHasStop); |
| | | return result; |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | if (_scheduler.IsShutdown && _scheduler.IsStarted) |
| | | if (_scheduler.IsShutdown || !_scheduler.IsStarted) |
| | | { |
| | | // 从Factory中获取Scheduler实例 |
| | | NameValueCollection collection = new NameValueCollection |
| | |
| | | /// <returns></returns> |
| | | private ITrigger CreateSimpleTrigger(DispatchInfoDTO sysSchedule) |
| | | { |
| | | // Quartz要求间隔至少1秒,防止数据库中IntervalSecond为0或负值导致ArgumentOutOfRangeException |
| | | var intervalSeconds = sysSchedule.IntervalSecond <= 0 ? 1 : sysSchedule.IntervalSecond; |
| | | |
| | | ITrigger trigger = TriggerBuilder.Create() |
| | | .WithIdentity(sysSchedule.Id.ToString(), sysSchedule.JobGroup) |
| | | .StartAt(sysSchedule.BeginTime.GetValueOrDefault()) |
| | | .WithSimpleSchedule(x => x |
| | | .WithIntervalInSeconds(sysSchedule.IntervalSecond) |
| | | .WithIntervalInSeconds(intervalSeconds) |
| | | .RepeatForever() |
| | | ) |
| | | .EndAt(sysSchedule.EndTime.GetValueOrDefault()) |