Ejemplo n.º 1
0
        private void PrepareTaskQueue()
        {
            this.m_TaskQueue.Clear();
            Type[] baseInAssemblies = this.FindTypesByBaseInAssemblies(this.FindAssembliesByNameKeyInAppDomain("T_"), typeof(TaskBase));
            Array  tasksInfo        = this.GetTasksInfo();
            bool   flag             = tasksInfo == null;

            if (flag)
            {
                AppEventLog.Debug("task info is null");
            }
            else
            {
                Type[] array = baseInAssemblies;
                for (int i = 0; i < array.Length; i++)
                {
                    Type type = array[i];
                    foreach (TaskBase taskBase in tasksInfo)
                    {
                        bool flag2 = taskBase == null || taskBase.TaskResult == TaskExecResult.Executed;
                        if (flag2)
                        {
                            AppEventLog.Debug("task executed, pre task queue");
                        }
                        else
                        {
                            TaskBase task = (TaskBase)Activator.CreateInstance(type);
                            task.Init();
                            bool flag3 = taskBase.MdId.ToString() == task.MdId.ToString() && taskBase.ComId == task.ComId;
                            if (flag3)
                            {
                                task.JobId               = taskBase.JobId;
                                task.JobName             = taskBase.JobName;
                                task.MdId                = taskBase.MdId;
                                task.MdName              = taskBase.MdName;
                                task.ComId               = taskBase.ComId;
                                task.ExecUserId          = taskBase.ExecUserId;
                                task.FailNoticeUserId    = taskBase.FailNoticeUserId;
                                task.RequiredExecuteTime = taskBase.RequiredExecuteTime;
                                task.ExecuteTime         = taskBase.ExecuteTime;
                                task.NextExecuteTime     = taskBase.NextExecuteTime;
                                task.CycleOption         = taskBase.CycleOption;
                                this.AddTask(task);
                                string str  = taskBase.MdId.ToString();
                                string str2 = "|";
                                string str3 = task.MdId.ToString();
                                AppEventLog.Debug(str + str2 + str3);
                                AppEventLog.Debug(taskBase.ComId + "|" + task.ComId);
                                AppEventLog.Debug("task  mdid or comid compare");
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private static void SendErrorMsgToMail(TaskBase task)
 {
     try
     {
         bool flag = string.IsNullOrEmpty(task.FailNoticeUserId);
         if (!flag)
         {
             SmsUtils.Send(task.FailNoticeUserId, string.Concat(new string[]
             {
                 "作业信息:<br/>应执行时间:",
                 task.RequiredExecuteTime.ToString(),
                 "<br/>实际执行时间:",
                 DateTime.Now.ToString(),
                 "<br/>执行失败!"
             }));
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 3
0
        public void Execute()
        {
            DateTime now = DateTime.Now;

            this.Init();
            TaskBase[] taskBaseArray = this.DequeueTasks(DateTime.Now);
            TaskBase[] array         = taskBaseArray;
            for (int i = 0; i < array.Length; i++)
            {
                TaskBase taskBase = array[i];
                bool     flag     = !this.UpdateNextTime(taskBase.JobId, taskBase.ExecuteTime, taskBase.NextExecuteTime);
                if (flag)
                {
                    taskBase.TaskResult = TaskExecResult.Executed;
                }
            }
            AppEventLog.Debug("tasks:" + taskBaseArray.Length.ToString());
            TaskBase[] array2 = taskBaseArray;
            for (int j = 0; j < array2.Length; j++)
            {
                TaskBase task = array2[j];
                try
                {
                    bool flag2 = task.TaskResult == TaskExecResult.Executed;
                    if (flag2)
                    {
                        AppEventLog.Debug("TaskResult:true.");
                    }
                    bool flag3 = task.TaskResult != TaskExecResult.Executed;
                    if (flag3)
                    {
                        DateTime dateTime = this.AddZQ(now, task.RequiredExecuteTime, task.CycleOption.CycleUnit, task.CycleOption.CycleValue, task.CycleOption.CycleExecWeek, task.CycleOption.CycleExecMonth, task.CycleOption.CycleExecTime);
                        bool     flag4    = DateTime.Compare(dateTime, now) < 0;
                        if (flag4)
                        {
                            bool skipExecute = task.SkipExecute;
                            if (skipExecute)
                            {
                                task.TaskResult = TaskExecResult.Skip;
                                List <string> list   = task.LogInfoDetail;
                                string        format = "{0} C|跳过 {1} 作业计划已过期,跳过该次运行。";
                                string        str    = DateTime.Now.ToString();
                                string        str2   = task.RequiredExecuteTime.ToString();
                                string        str3   = string.Format(format, str, str2);
                                list.Add(str3);
                                while (DateTime.Compare(this.AddZQ(now, dateTime, task.CycleOption.CycleUnit, task.CycleOption.CycleValue, task.CycleOption.CycleExecWeek, task.CycleOption.CycleExecMonth, task.CycleOption.CycleExecTime), now) < 0)
                                {
                                    task.RequiredExecuteTime = dateTime;
                                    dateTime        = this.AddZQ(now, dateTime, task.CycleOption.CycleUnit, task.CycleOption.CycleValue, task.CycleOption.CycleExecWeek, task.CycleOption.CycleExecMonth, task.CycleOption.CycleExecTime);
                                    task.TaskResult = TaskExecResult.Skip;
                                    List <string> list2   = task.LogInfoDetail;
                                    string        format2 = "{0} C|跳过 {1} 作业计划已过期,跳过该次运行。";
                                    string        str4    = DateTime.Now.ToString();
                                    string        str5    = task.RequiredExecuteTime.ToString();
                                    string        str6    = string.Format(format2, str4, str5);
                                    list2.Add(str6);
                                }
                                JobLogUtils.WriteServiceLog(task);
                            }
                            else
                            {
                                task.NextExecuteTime = dateTime;
                                TimerJob timerJob = new TimerJob();
                                timerJob.TaskModule = task;
                                TimerManager.RunTask(timerJob, task.ExecUserId, AppConfig.DefaultDbId);
                                while (DateTime.Compare(this.AddZQ(now, dateTime, task.CycleOption.CycleUnit, task.CycleOption.CycleValue, task.CycleOption.CycleExecWeek, task.CycleOption.CycleExecMonth, task.CycleOption.CycleExecTime), now) < 0)
                                {
                                    task.RequiredExecuteTime = dateTime;
                                    dateTime             = this.AddZQ(now, dateTime, task.CycleOption.CycleUnit, task.CycleOption.CycleValue, task.CycleOption.CycleExecWeek, task.CycleOption.CycleExecMonth, task.CycleOption.CycleExecTime);
                                    task.NextExecuteTime = dateTime;
                                    timerJob.TaskModule  = task;
                                    TimerManager.RunTask(timerJob, task.ExecUserId, AppConfig.DefaultDbId);
                                }
                                bool flag5 = task.TaskResult != TaskExecResult.Failure && task.TaskResult != TaskExecResult.Exception;
                                if (flag5)
                                {
                                    task.TaskResult = TaskExecResult.Success;
                                }
                                JobLogUtils.WriteServiceLog(task);
                            }
                            bool flag6 = DateTime.Compare(dateTime, now) < 0;
                            if (flag6)
                            {
                                task.RequiredExecuteTime = dateTime;
                                task.NextExecuteTime     = this.AddZQ(now, dateTime, task.CycleOption.CycleUnit, task.CycleOption.CycleValue, task.CycleOption.CycleExecWeek, task.CycleOption.CycleExecMonth, task.CycleOption.CycleExecTime);
                                TimerManager.RunTask(new TimerJob
                                {
                                    TaskModule = task
                                }, task.ExecUserId, AppConfig.DefaultDbId);
                                bool flag7 = task.TaskResult != TaskExecResult.Failure && task.TaskResult != TaskExecResult.Exception;
                                if (flag7)
                                {
                                    task.TaskResult = TaskExecResult.Success;
                                }
                                JobLogUtils.WriteServiceLog(task);
                            }
                        }
                        else
                        {
                            TimerManager.RunTask(new TimerJob
                            {
                                TaskModule = task
                            }, task.ExecUserId, AppConfig.DefaultDbId);
                            bool flag8 = task.TaskResult != TaskExecResult.Failure && task.TaskResult != TaskExecResult.Exception;
                            if (flag8)
                            {
                                task.TaskResult = TaskExecResult.Success;
                            }
                            JobLogUtils.WriteServiceLog(task);
                        }
                    }
                }
                catch (Exception ex_4E3)
                {
                    task.TaskResult = TaskExecResult.Exception;
                    JobLogUtils.WriteServiceLog(task);
                }
            }
        }
Ejemplo n.º 4
0
        private Array GetTasksInfo()
        {
            TaskBase[] Result     = null;
            DateTime   dtNextTime = default(DateTime);
            DateTime   dtCurTime  = AppRuntime.ServerDateTime.ToString().ToDateTime();
            bool       executed   = false;
            Database   db         = LogicContext.GetDatabase();
            HSQL       hsql       = new HSQL(db);

            hsql.Add("select JOB_JOBID,JOB_JOBNAME,JOB_MDID,JOB_STATUS,JOB_CYCLEUNIT,JOB_CYCLEVALUE");
            hsql.Add(",JOB_EXECTIME,JOB_EXECWEEK,JOB_EXECMONTH,JOB_BEGINTIME,JOB_ENDTIME,JOB_EXECUSERID,JOB_FAILNOTICEUSERID");
            hsql.Add(",JOB_PREEXECTIME,JOB_PREEXECSTATUS,JOB_PREEXECDESC,JOB_NEXTEXECTIME");
            hsql.Add(",JOB_STARTTIME,JOB_STOPTIME,JOB_REMARKS,MODULE_COMID,MODULE_MDNAME");
            hsql.Add(" from JOB left join MODULE on MODULE_MDID = JOB_MDID ");
            hsql.Add(" where JOB_STATUS = 'D'");
            hsql.Add(" and JOB_BEGINTIME <= :NOWEXECTIME and JOB_BEGINTIME is not NULL and (JOB_ENDTIME > :NOWEXECTIME or JOB_ENDTIME IS NULL) ");
            hsql.Add(" and (JOB_NEXTEXECTIME < :NOWEXECTIME or JOB_NEXTEXECTIME is NULL)  ");
            hsql.Add("order by JOB_NEXTEXECTIME");
            hsql.ParamByName("NOWEXECTIME").Value = dtCurTime;
            DataSet ds   = db.OpenDataSet(hsql);
            bool    flag = ds.Tables[0].Rows.Count > 0;

            if (flag)
            {
                Result = new TaskBase[ds.Tables[0].Rows.Count];
            }
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                int    JOB_JOBID            = ds.Tables[0].Rows[i]["JOB_JOBID"].ToString().ToInt();
                string JOB_JOBNAME          = ds.Tables[0].Rows[i]["JOB_JOBNAME"].ToString().Trim();
                int    JOB_MDID             = ds.Tables[0].Rows[i]["JOB_MDID"].ToString().ToInt();
                string MDNAME               = ds.Tables[0].Rows[i]["MODULE_MDNAME"].ToString().Trim();
                string COMID                = ds.Tables[0].Rows[i]["MODULE_COMID"].ToString().Trim();
                string JOB_EXECUSERID       = ds.Tables[0].Rows[i]["JOB_EXECUSERID"].ToString().Trim();
                string JOB_FAILNOTICEUSERID = ds.Tables[0].Rows[i]["JOB_FAILNOTICEUSERID"].ToString().Trim();
                string JOB_NEXTEXECTIME     = string.IsNullOrEmpty(ds.Tables[0].Rows[i]["JOB_NEXTEXECTIME"].ToString()) ? ds.Tables[0].Rows[i]["JOB_BEGINTIME"].ToString() : ds.Tables[0].Rows[i]["JOB_NEXTEXECTIME"].ToString();
                string JOB_CYCLEUNIT        = ds.Tables[0].Rows[i]["JOB_CYCLEUNIT"].ToString().Trim();
                int    JOB_CYCLEVALUE       = ds.Tables[0].Rows[i]["JOB_CYCLEVALUE"].ToString().Trim().ToInt();
                string JOB_EXECTIME         = ds.Tables[0].Rows[i]["JOB_EXECTIME"].ToString().Trim();
                string JOB_EXECWEEK         = ds.Tables[0].Rows[i]["JOB_EXECWEEK"].ToString().Trim();
                string JOB_EXECMONTH        = ds.Tables[0].Rows[i]["JOB_EXECMONTH"].ToString().Trim();
                string JOB_BEGINTIME        = ds.Tables[0].Rows[i]["JOB_BEGINTIME"].ToString().Trim();
                bool   flag2                = string.IsNullOrEmpty(JOB_CYCLEUNIT) || JOB_CYCLEVALUE <= 0;
                if (!flag2)
                {
                    string a = JOB_CYCLEUNIT;
                    if (!(a == "MONTH"))
                    {
                        if (!(a == "WEEK"))
                        {
                            if (!(a == "DAY"))
                            {
                                if (!(a == "MINUTE"))
                                {
                                    goto IL_6D3;
                                }
                            }
                            else
                            {
                                bool flag3 = string.IsNullOrEmpty(JOB_EXECTIME);
                                if (flag3)
                                {
                                    goto IL_6D3;
                                }
                            }
                        }
                        else
                        {
                            bool flag4 = string.IsNullOrEmpty(JOB_EXECWEEK) || string.IsNullOrEmpty(JOB_EXECTIME) || JOB_EXECMONTH.Length != 7;
                            if (flag4)
                            {
                                goto IL_6D3;
                            }
                        }
                    }
                    else
                    {
                        bool flag5 = string.IsNullOrEmpty(JOB_EXECMONTH) || string.IsNullOrEmpty(JOB_EXECTIME) || JOB_EXECMONTH.Length != 32;
                        if (flag5)
                        {
                            goto IL_6D3;
                        }
                    }
                    bool flag6 = string.IsNullOrEmpty(ds.Tables[0].Rows[i]["JOB_NEXTEXECTIME"].ToString());
                    if (flag6)
                    {
                        JOB_NEXTEXECTIME = this.AddZQ(dtCurTime, JOB_BEGINTIME.ToDateTime(), JOB_CYCLEUNIT, JOB_CYCLEVALUE, JOB_EXECWEEK, JOB_EXECMONTH, JOB_EXECTIME).ToString();
                    }
                    dtNextTime = this.AddZQ(dtCurTime, JOB_NEXTEXECTIME.ToDateTime(), JOB_CYCLEUNIT, JOB_CYCLEVALUE, JOB_EXECWEEK, JOB_EXECMONTH, JOB_EXECTIME);
                    bool flag7 = dtNextTime.Equals(default(DateTime));
                    if (!flag7)
                    {
                        TaskBase obj   = new TaskBase();
                        bool     flag8 = DateTime.Compare(dtNextTime, dtCurTime) < 0;
                        if (flag8)
                        {
                            while (DateTime.Compare(this.AddZQ(dtCurTime, dtNextTime, JOB_CYCLEUNIT, JOB_CYCLEVALUE, JOB_EXECWEEK, JOB_EXECMONTH, JOB_EXECTIME), dtCurTime) < 0)
                            {
                                dtNextTime = this.AddZQ(dtCurTime, dtNextTime, JOB_CYCLEUNIT, JOB_CYCLEVALUE, JOB_EXECWEEK, JOB_EXECMONTH, JOB_EXECTIME);
                            }
                            bool flag9 = !this.UpdateNextTime(JOB_JOBID, JOB_NEXTEXECTIME.ToDateTime(), dtNextTime);
                            if (flag9)
                            {
                                executed = true;
                            }
                            obj.ExecuteTime     = dtNextTime;
                            obj.NextExecuteTime = this.AddZQ(dtCurTime, dtNextTime, JOB_CYCLEUNIT, JOB_CYCLEVALUE, JOB_EXECWEEK, JOB_EXECMONTH, JOB_EXECTIME);
                            bool flag10 = executed;
                            if (flag10)
                            {
                                obj.TaskResult = TaskExecResult.Executed;
                                executed       = false;
                            }
                        }
                        else
                        {
                            obj.ExecuteTime     = JOB_NEXTEXECTIME.ToDateTime();
                            obj.NextExecuteTime = dtNextTime;
                        }
                        obj.JobId                      = JOB_JOBID;
                        obj.JobName                    = JOB_JOBNAME;
                        obj.MdId                       = JOB_MDID;
                        obj.MdName                     = MDNAME;
                        obj.ComId                      = COMID;
                        obj.ExecUserId                 = JOB_EXECUSERID;
                        obj.FailNoticeUserId           = JOB_FAILNOTICEUSERID;
                        obj.RequiredExecuteTime        = (string.IsNullOrEmpty(JOB_NEXTEXECTIME) ? dtCurTime : JOB_NEXTEXECTIME.ToDateTime());
                        obj.CycleOption.CycleUnit      = JOB_CYCLEUNIT;
                        obj.CycleOption.CycleValue     = JOB_CYCLEVALUE;
                        obj.CycleOption.CycleExecTime  = JOB_EXECTIME;
                        obj.CycleOption.CycleExecWeek  = JOB_EXECWEEK;
                        obj.CycleOption.CycleExecMonth = JOB_EXECMONTH;
                        Result[i]                      = obj;
                    }
                }
                IL_6D3 :;
            }
            return(Result);
        }
Ejemplo n.º 5
0
        public static void WriteServiceLog(TaskBase task)
        {
            Database database = LogicContext.GetDatabase();

            try
            {
                database.BeginTrans();
                HSQL sql = new HSQL(database);
                sql.Add("insert into JOBLOG(JOBLOG_JOBID, JOBLOG_LOGNO, JOBLOG_LOGTIME, JOBLOG_OPERTYPE, JOBLOG_EXECRESULT, JOBLOG_DESC, JOBLOG_DETAIL)");
                sql.Add("values(:JOBLOG_JOBID, :JOBLOG_LOGNO, :JOBLOG_LOGTIME, :JOBLOG_OPERTYPE, :JOBLOG_EXECRESULT, :JOBLOG_DESC, :JOBLOG_DETAIL)");
                sql.ParamByName("JOBLOG_JOBID").Value    = task.JobId;
                sql.ParamByName("JOBLOG_LOGNO").Value    = TimIdUtils.GenUtoId("JOBLOGNO");
                sql.ParamByName("JOBLOG_LOGTIME").Value  = AppRuntime.ServerDateTime;
                sql.ParamByName("JOBLOG_OPERTYPE").Value = "E";
                sql.ParamByName("JOBLOG_DETAIL").Value   = string.Empty;
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string str in task.LogInfoDetail)
                {
                    stringBuilder.AppendLine(str);
                }
                string str2 = stringBuilder.ToString();
                string str3 = string.Empty;
                bool   flag = task.TaskResult == TaskExecResult.Success;
                if (flag)
                {
                    str3 = string.Format("{0} 作业计划执行成功。", task.RequiredExecuteTime.ToString());
                    bool flag2 = string.IsNullOrEmpty(str2);
                    if (flag2)
                    {
                        str2 = str3;
                    }
                    sql.ParamByName("JOBLOG_EXECRESULT").Value = "A";
                    sql.ParamByName("JOBLOG_DESC").Value       = str3;
                    sql.AddParam("JOBLOG_DETAIL", TimDbType.Blob, 0, str2);
                }
                else
                {
                    bool flag3 = task.TaskResult == TaskExecResult.Failure;
                    if (flag3)
                    {
                        str3 = string.Format("{0} 作业计划执行失败。", task.RequiredExecuteTime.ToString());
                        bool flag4 = string.IsNullOrEmpty(str2);
                        if (flag4)
                        {
                            str2 = str3;
                        }
                        sql.ParamByName("JOBLOG_EXECRESULT").Value = "B";
                        sql.ParamByName("JOBLOG_DESC").Value       = str3;
                        sql.AddParam("JOBLOG_DETAIL", TimDbType.Blob, 0, str2);
                        JobLogUtils.SendErrorMsgToMail(task);
                    }
                    else
                    {
                        bool flag5 = task.TaskResult == TaskExecResult.Skip;
                        if (flag5)
                        {
                            str3 = "部分作业计划已过期,跳过运行。";
                            bool flag6 = string.IsNullOrEmpty(str2);
                            if (flag6)
                            {
                                str2 = str3;
                            }
                            sql.ParamByName("JOBLOG_EXECRESULT").Value = "C";
                            sql.ParamByName("JOBLOG_DESC").Value       = str3;
                            sql.AddParam("JOBLOG_DETAIL", TimDbType.Blob, 0, str2);
                        }
                        else
                        {
                            bool flag7 = task.TaskResult == TaskExecResult.Exception;
                            if (flag7)
                            {
                                str3 = string.Format("{0} 作业计划执行错误。", task.RequiredExecuteTime.ToString());
                                bool flag8 = string.IsNullOrEmpty(str2);
                                if (flag8)
                                {
                                    str2 = str3;
                                }
                                sql.ParamByName("JOBLOG_EXECRESULT").Value = "D";
                                sql.ParamByName("JOBLOG_DESC").Value       = str3;
                                sql.AddParam("JOBLOG_DETAIL", TimDbType.Blob, 0, str2);
                                JobLogUtils.SendErrorMsgToMail(task);
                            }
                            else
                            {
                                bool flag9 = task.TaskResult == TaskExecResult.StartExecute;
                                if (flag9)
                                {
                                    str3 = string.Format("{0} 作业计划开始执行。", task.RequiredExecuteTime.ToString());
                                    bool flag10 = string.IsNullOrEmpty(str2);
                                    if (flag10)
                                    {
                                        str2 = str3;
                                    }
                                    sql.ParamByName("JOBLOG_EXECRESULT").Value = "A";
                                    sql.ParamByName("JOBLOG_DESC").Value       = str3;
                                    sql.AddParam("JOBLOG_DETAIL", TimDbType.Blob, 0, str2);
                                }
                            }
                        }
                    }
                }
                database.ExecSQL(sql);
                task.LogInfoDetail.Clear();
                sql.Clear();
                sql.Add("update JOB set JOB_PREEXECTIME = :JOB_PREEXECTIME,JOB_PREEXECSTATUS = :JOB_PREEXECSTATUS,JOB_PREEXECDESC = :JOB_PREEXECDESC ");
                sql.Add(" where JOB_JOBID = :JOB_JOBID");
                sql.ParamByName("JOB_PREEXECSTATUS").Value = ((task.TaskResult != TaskExecResult.Success) ? ((task.TaskResult != TaskExecResult.Failure) ? ((task.TaskResult != TaskExecResult.Exception) ? "C" : "D") : "B") : "A");
                sql.ParamByName("JOB_PREEXECTIME").Value   = task.ExecuteTime;
                sql.ParamByName("JOB_PREEXECDESC").Value   = str3;
                sql.ParamByName("JOB_JOBID").Value         = task.JobId;
                database.ExecSQL(sql);
                database.CommitTrans();
            }
            catch (Exception ex)
            {
                database.RollbackTrans();
                AppEventLog.Error("记录作业计划日志失败,原因:" + ex.Message);
            }
        }