Пример #1
0
        /// <summary>
        /// 读取在时间范围内,没有执行过且没有正在运行任务的作业。然后转换为任务并且入库
        /// </summary>
        /// <param name="batchCount"></param>
        /// <param name="timeOffset"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public SysTaskCollection FetchNotDispatchedJobsAndConvertToTask(int batchCount, TimeSpan timeOffset, Action <JobBase, SysTask> action)
        {
            SysTaskCollection result = new SysTaskCollection();

            FetchNotDispatchedJobs(batchCount, timeOffset, job =>
            {
                JobSchedule matchedSchedule = null;

                if (job.CanStart(timeOffset, out matchedSchedule))
                {
                    SysTask task = job.ToSysTask();

                    task.FillData(BuildTaskExtraData(job, timeOffset, matchedSchedule));

                    job.SetCurrentJobBeginStatus();
                    SysTaskAdapter.Instance.Update(task);

                    if (action != null)
                    {
                        action(job, task);
                    }

                    result.Add(task);
                }
            });

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 是否可以执行
        /// </summary>
        /// <param name="timeOffset"></param>
        /// <param name="matchedSchedule">返回匹配的计划对象</param>
        /// <returns></returns>
        public virtual bool CanStart(TimeSpan timeOffset, out JobSchedule matchedSchedule)
        {
            bool     result      = false;
            DateTime lastExeTime = LastStartExecuteTime ?? default(DateTime);
            DateTime now         = DateTime.Now;

            matchedSchedule = null;

            foreach (JobSchedule schedule in Schedules)
            {
                result = schedule.Enabled && schedule.IsNextExecuteTime(lastExeTime, now, timeOffset);

                if (result)
                {
                    matchedSchedule = schedule;
                    break;
                }
            }

            return(result);
        }
Пример #3
0
        private static Dictionary <string, string> BuildTaskExtraData(JobBase job, TimeSpan timeOffset, JobSchedule matchedSchedule)
        {
            Dictionary <string, string> extraData = new Dictionary <string, string>();

            if (job.LastStartExecuteTime != null)
            {
                extraData.Add("LastStartExecuteTime", job.LastStartExecuteTime.Value.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            }

            if (matchedSchedule != null)
            {
                extraData.Add("ScheduleID", matchedSchedule.ID);
            }

            extraData.Add("TimeOffset", timeOffset.TotalSeconds.ToString("#,##0.00"));

            return(extraData);
        }
Пример #4
0
        /// <summary>
        /// 是否可以执行
        /// </summary>
        /// <param name="timeOffset"></param>
        /// <returns></returns>
        public virtual bool CanStart(TimeSpan timeOffset)
        {
            JobSchedule matchedSchedule = null;

            return(CanStart(timeOffset, out matchedSchedule));
        }