private void Report(IJob job, JobItem ji, Object ext = null)
 {
     try
     {
         Ant.Report(ji, ext);
     }
     catch (Exception ex)
     {
         XTrace.WriteLine("[{0}]的[{1}]状态报告失败!{2}", job, ji.Status, ex.GetTrue().Message);
     }
 }
Exemple #2
0
        /// <summary>申请任务</summary>
        /// <param name="job">作业</param>
        /// <param name="data">扩展数据</param>
        /// <param name="count">要申请的任务个数</param>
        /// <returns></returns>
        public override IJobItem[] Acquire(IJob job, IDictionary <String, Object> data, Int32 count)
        {
            var list = new List <IJobItem>();

            if (!job.Enable)
            {
                return(list.ToArray());
            }

            // 当前时间减去偏移量,作为当前时间。数据抽取不许超过该时间
            var now = DateTime.Now.AddSeconds(-job.Offset);
            // 避免毫秒级带来误差,每毫秒有10000个滴答
            var sec = now.Ticks / 1_000_0000;

            now = new DateTime(sec * 1_000_0000);

            var step = job.Step;

            if (step <= 0)
            {
                step = 30;
            }

            var start = job.Start;

            for (var i = 0; i < count; i++)
            {
                // 开始时间和结束时间是否越界
                if (start >= now)
                {
                    break;
                }

                var end = start.AddSeconds(step);
                // 任务结束时间超过作业结束时间时,取后者
                if (job.End.Year > 2000 && end > job.End)
                {
                    end = job.End;
                }

                // 时间片必须严格要求按照步进大小分片,除非有合适的End
                if (job.Mode != JobModes.Alarm)
                {
                    if (end > now)
                    {
                        break;
                    }
                }

                // 时间区间判断
                if (start >= end)
                {
                    break;
                }

                // 切分新任务
                var set = new JobItem
                {
                    Start     = start,
                    End       = end,
                    Step      = job.Step,
                    Offset    = job.Offset,
                    BatchSize = job.BatchSize,
                };

                // 更新任务
                job.Start = end;
                start     = end;

                list.Add(set);
            }

            if (list.Count > 0)
            {
                _File.UpdateTime = DateTime.Now;
                _File.SaveAsync();
            }

            return(list.ToArray());
        }