private int TaskManager_OnTaskExecBefore(ExecTaskInfo task) { int logId = 0; try { Ts_ExecLog tsLog = new Ts_ExecLog(); tsLog.ExecParams = task.Params; tsLog.ExecStatrtTime = task.LastExecTime; tsLog.ExecUrl = task.ExecUrl; tsLog.TaskGuid = task.Guid; logId = (int)_ormExecLog.Add(tsLog); } catch (Exception ex) { log.ErrorAndEmail(string.Format("保存执行日志结果异常TaskManager_OnTaskExecBefore,参数:{0}", task.ToJson()), ex); } try { Ts_TaskExec taskExec = new Ts_TaskExec(); taskExec.LastExecId = logId; taskExec.LastExecTime = task.LastExecTime; taskExec.TaskGuid = task.Guid; _ormTaskExec.Update(taskExec); } catch (Exception ex) { log.ErrorAndEmail(string.Format("修改最后一次执行时间异常TaskManager_OnTaskExecBefore,参数:{0}", task.ToJson()), ex); } return(logId); }
private void TaskManager_OnTaskExecAfter(TaskExecLog taskExecLog, TaskExecResult result) { try { Ts_ExecLog tsLog = new Ts_ExecLog(); tsLog.ExecEndTime = taskExecLog.ExecEndTime; result.Data = result.Data ?? string.Empty; tsLog.ExecResult = result.ToJson(); if (tsLog.ExecResult.Length > 2000) { tsLog.ExecResult = tsLog.ExecResult.Substring(0, 2000); } tsLog.ExecResultCode = result.Code; tsLog.ExecStatrtTime = taskExecLog.ExecStatrtTime; if (_ormExecLog.Update(tsLog, w => w.Id == taskExecLog.ExecLogId) != 1) { log.Error(string.Format("执行后更新记录异常,logId={0},结果:{1}", taskExecLog.ExecLogId, tsLog.ExecResult)); } } catch (Exception ex) { log.ErrorAndEmail(string.Format("保存执行日志结果异常TaskManager_OnTaskExecAfter,参数:{0}", taskExecLog.ToJson()), ex); } try { Ts_TaskExec taskExec = new Ts_TaskExec(); taskExec.LastExecResultCode = result.Code; _ormTaskExec.Update(taskExec, w => w.TaskGuid == taskExecLog.ExecGuid); } catch (Exception ex) { log.ErrorAndEmail(string.Format("修改执行Code异常TaskManager_OnTaskExecAfter,参数:{0}", taskExecLog.ToJson()), ex); } if (result.Code != 0 && taskExecLog.IsErrorAlert) { _mailService.SendEmail(string.Format("任务【{0}】执行异常", taskExecLog.Title), string.Format("您的任务:{0}\r\n执行异常:\r\n{1}", taskExecLog.Title, result.Data), taskExecLog.ReceiveEmail); } }