Exemplo n.º 1
0
        /// <summary>
        /// 更新作业的执行情况
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public string UpdateJobExcuteInfo(PsbJobStatus job)
        {
            try
            {
                string            sql   = @"update psb_job_status set 
                                        jobstatus = :jobStatus,
                                        excuteresult = :excuteresult,
                                        lastexcutetime = :lastexcutetime,
                                        maxexcutetime = :maxexcutetime,
                                        minexcutetime = :minexcutetime,
                                        avgexcutetime = :avgexcutetime,
                                        excutecount = :excutecount,
                                        totalexcutetime = :totalexcutetime
                                  where jobno = :jobno";
                DynamicParameters paras = new DynamicParameters();
                paras.Add("jobStatus", job.JobStatus);
                paras.Add("excuteresult", job.ExcuteResult);
                paras.Add("lastexcutetime", job.LastExcuteTime);
                paras.Add("maxexcutetime", job.MaxExcuteTime);
                paras.Add("minexcutetime", job.MinExcuteTime);
                paras.Add("avgexcutetime", job.AvgExcuteTime);
                paras.Add("excutecount", job.ExcuteCount);
                paras.Add("totalexcutetime", job.TotalExcuteTime);
                paras.Add("jobno", job.JobNo);

                Db.Connection.Execute(sql, paras);
                return(string.Empty);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 执行作业
 /// </summary>
 /// <param name="job"></param>
 /// <returns></returns>
 public string ExcuteJob(PsbJobStatus job)
 {
     try
     {
         Db.Connection.Execute(job.SpName, commandType: CommandType.StoredProcedure);
         return(string.Empty);
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 执行指定的作业
        /// </summary>
        /// <param name="job"></param>
        private void ExcuteJob(PsbJobStatus job)
        {
            //判断作业是否临时挂起
            if (job.IfSuspend)
            {
                return;
            }
            if (job.UsedFlag == 0)
            {
                return;
            }
            if (job.ExcuteStatus == 0 || job.ExcuteStatus == 2)
            {
                //判断是否达到执行时间间隔
                var excuteFinishDuration = Convert.ToInt64((DateTime.Now - job.FinishExcuteTime).TotalSeconds);
                if (excuteFinishDuration < job.Interval)
                {
                    return;
                }
                //达到执行时间间隔,执行作业
                job.StartExcuteTime = DateTime.Now;
                job.LastExcuteTime  = DateTime.Now;
                job.ExcuteStatus    = 1;
                job.JobStatus       = 1;
                Task.Run(() =>
                {
                    //执行作业
                    string result        = _JobBiz.ExcuteJob(job);
                    job.FinishExcuteTime = DateTime.Now;
                    if (!string.IsNullOrWhiteSpace(result))
                    {
                        job.ExcuteStatus = 0;
                        job.JobStatus    = 3;
                        job.ExcuteResult = result;
                        ShowInfo($"作业({job.JobNo}) 执行失败:{result}");
                        return;
                    }
                    //作业第一次执行不统计信息
                    if (job.IfFirstExcute)
                    {
                        job.ExcuteStatus  = 2;
                        job.JobStatus     = 2;
                        job.IfFirstExcute = false;
                        return;
                    }
                    //统计信息
                    var excuteDuration = Convert.ToInt32((job.FinishExcuteTime - job.StartExcuteTime).TotalMilliseconds);
                    if (job.ExcuteCount > 0)
                    {
                        job.TotalExcuteTime += excuteDuration;
                        job.ExcuteCount++;
                        job.AvgExcuteTime = job.TotalExcuteTime / job.ExcuteCount;

                        if (excuteDuration > job.MaxExcuteTime)
                        {
                            job.MaxExcuteTime = excuteDuration;
                        }
                        if (excuteDuration < job.MinExcuteTime)
                        {
                            job.MinExcuteTime = excuteDuration;
                        }
                    }
                    else
                    {
                        job.ExcuteCount     = 1;
                        job.MaxExcuteTime   = excuteDuration;
                        job.MinExcuteTime   = excuteDuration;
                        job.AvgExcuteTime   = excuteDuration;
                        job.TotalExcuteTime = excuteDuration;
                    }
                    //更新作业执行信息
                    result = _JobBiz.UpdateJobExcuteInfo(job);
                    if (!string.IsNullOrWhiteSpace(result))
                    {
                        job.ExcuteStatus = 2;
                        job.JobStatus    = 3;
                        job.ExcuteResult = result;
                        ShowInfo($"作业({job.JobNo}) 执行失败:{result}");
                        return;
                    }
                    job.ExcuteResult = "执行成功";
                    job.ExcuteStatus = 2;
                    job.JobStatus    = 2;
                    ShowInfo($"作业({job.JobNo}) 执行成功,耗时(ms) {excuteDuration}");
                });
            }
        }