/// <summary> /// 任务执行后 /// </summary> /// <param name="task">任务</param> /// <param name="result">结果</param> private void OnTaskExecuted(T task, DelayTaskExecResult result) { if (task.LoopInterval > 0) { this.AddDelay(task.ID, task.LoopInterval); task.IsExecuting = false; } else { this.Remove(task.ID, false); task.IsExecuting = false; } DatabaseHelper.AddExecResult <T>(result); }
/// <summary> /// 添加执行结果记录 /// </summary> /// <param name="result">执行结果</param> /// <returns></returns> public static bool AddExecResult <T>(DelayTaskExecResult result) where T : DelayTask, new() { using (var db = new DatabaseContext()) { if (result.Success == true) { db.Set <T>().Where(item => item.ID == result.DelayTaskID).Update(item => new T { SuccessCount = item.SuccessCount + 1 }); } else { db.Set <T>().Where(item => item.ID == result.DelayTaskID).Update(item => new T { FailureCount = item.FailureCount + 1 }); } db.DelayTaskExecResult.Add(result); return(db.SaveChanges() > 0); } }