Exemple #1
0
        public TaskRound Create(TaskType type)
        {
            DataContext dc = new DataContext(this.DbString);
            TaskRound   tr = new TaskRound()
            {
                createdAt  = DateTime.Now,
                taskStatus = (int)TaskRoundStatus.Waiting,
                taskType   = (int)type,
                uuid       = Guid.NewGuid()
            };

            dc.Context.GetTable <TaskRound>().InsertOnSubmit(tr);
            dc.Context.SubmitChanges();
            return(tr);
        }
Exemple #2
0
        public void FinishTaskByUniqId(Guid uuid, string result, bool error = false)
        {
            DataContext dc = new DataContext(this.DbString);
            TaskRound   tr = dc.Context.GetTable <TaskRound>().Where(s => s.uuid.Equals(uuid)).FirstOrDefault();

            if (tr == null)
            {
                throw new TaskRoundNotFoundException();
            }

            tr.taskStatus = error ? (int)TaskRoundStatus.Cancel : (int)TaskRoundStatus.Finish;
            tr.finishAt   = DateTime.Now;
            tr.result     = result;

            dc.Context.SubmitChanges();
        }
Exemple #3
0
        /// <summary>
        /// 分发任务
        /// </summary>
        /// <param name="ts"></param>
        public void Dispatch(TaskSetting ts)
        {
            ITaskRoundService trs       = new TaskRoundService(this.DbString);
            TaskRound         taskRound = null;

            try
            {
                if (ts.LogTaskRound)
                {
                    taskRound = trs.Create(ts.TaskType);
                }
                LogUtil.Logger.Info("获取到任务信息:");
                LogUtil.Logger.Info(ts.TaskType);
                LogUtil.Logger.Info(ts.JsonParameter);
                switch (ts.TaskType)
                {
                case TaskType.CalAtt:
                    CalAttParameter          calAtt = JSONHelper.parse <CalAttParameter>(ts.JsonParameter);
                    IAttendanceRecordService ars    = new AttendanceRecordService(this.DbString);
                    //ars.CalculateAttendRecord(calAtt.AttCalculateDateTime, calAtt.ShiftCodes);
                    ars.CalculateAttendRecordWithExtrawork(calAtt.AttCalculateDateTime);
                    // add send email to queue
                    SendAttWarnEmailMessage(calAtt.AttCalculateDateTime, calAtt.ShiftCodes);
                    // create message record
                    SendAttWarnMsgRecordMessage(calAtt.AttCalculateDateTime, calAtt.ShiftCodes);
                    break;

                case TaskType.SendMail:
                    break;

                case TaskType.SendAttExceptionMail:
                    AttWarnEmailParameter       attWarn = JSONHelper.parse <AttWarnEmailParameter>(ts.JsonParameter);
                    IAttendanceRecordCalService arcs    = new AttendanceRecordCalService(this.DbString);
                    arcs.SendWarnEmail(attWarn.AttWarnDate);
                    break;

                case TaskType.ToFullMemeberWarn:
                    IMessageRecordService mrs = new MessageRecordService(this.DbString);
                    mrs.CreateToFullMemberMessage(ts.TaskCreateAt.Date);
                    break;

                case TaskType.AttExceptionWarn:
                    AttWarnParameter      attWarnP = JSONHelper.parse <AttWarnParameter>(ts.JsonParameter);
                    IMessageRecordService mrss     = new MessageRecordService(this.DbString);
                    mrss.CreateAttExceptionMessage(attWarnP.AttWarnDate);
                    break;

                case TaskType.ReStartSvc:
                    this.IsRestartSvc = true;
                    break;

                default:
                    throw new TaskTypeNotSupportException();
                }
                if (ts.LogTaskRound && taskRound != null)
                {
                    trs.FinishTaskByUniqId(taskRound.uuid, "任务运行成功");
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("{0}: {1}", ex.Message, ex.StackTrace);

                LogUtil.Logger.Error("任务执行错误:", ex);

                try
                {
                    if (ts.LogTaskRound && taskRound != null)
                    {
                        trs.FinishTaskByUniqId(taskRound.uuid, msg, true);
                    }
                }
                catch
                {
                }
                throw new Exception(msg, ex);
            }
        }