Esempio n. 1
0
 private void StopJob(JobTimer timer)
 {
     timer.Stop();
     timers.Remove(timer.Id);
     log.Info($"停止Job-{timer.Job.Name}");
     timer.Dispose();
 }
Esempio n. 2
0
        private void CheckTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                var jobs = jobService.GetServerJobs(Config.Server);
                foreach (var job in jobs)
                {
                    if (job.Status == JobStatus.Disable && timers.ContainsKey(job.Id))
                    {
                        StopJob(timers[job.Id]);
                    }

                    if (job.Status == JobStatus.Normal && !timers.ContainsKey(job.Id))
                    {
                        var result = jobHelper.CheckJob(log, job);
                        if (!result.Pass)
                        {
                            jobService.UpdateJobStatus(job, JobStatus.Abnormal, result.ErrorMessage);
                            log.Info($"{result.ErrorMessage}{job.ExecuteTarget}");
                            continue;
                        }

                        var timer = new JobTimer(job.Id, result.TimerInterval)
                        {
                            Job         = job,
                            CheckResult = result,
                            Config      = jobService.GetJobConfig(job.Id),
                            Enabled     = true
                        };
                        timer.Elapsed   += new ElapsedEventHandler(JobTimer_Elapsed);
                        timers[timer.Id] = timer;
                        timer.Start();
                        log.Info($"启动Job-{timer.Job.Name}");
                        System.Threading.Thread.Sleep(1000);
                    }
                }
            }
            catch (Exception ex)
            {
                JobHelper.SendExceptionMail("主服务轮询作业异常", ex.ToString());
            }
        }