public void UpdateTask(string id, PtiTasker tasker) { EventManager.Get().RegEvent(ptievent => { var task = this.TaskPool.Where(i => i.PtiTasker._id == id).FirstOrDefault(); if (task != null) { task.PtiTasker.Update(tasker); } else { } return(null); }, PtiEventType.UpdateTask); }
public void Update(PtiTasker tasker) { this.RunArgs = tasker.RunArgs; this.RunPath = tasker.RunPath; this.Schedule = tasker.Schedule; if (!string.IsNullOrWhiteSpace(tasker.ApplicationId)) { this.ApplicationId = tasker.ApplicationId; } if (!string.IsNullOrWhiteSpace(tasker.RunCmd)) { this.RunCmd = tasker.RunCmd; } if (!string.IsNullOrWhiteSpace(tasker.Schedule)) { } if (!string.IsNullOrWhiteSpace(tasker.TaskName)) { this.TaskName = tasker.TaskName; } }
public bool CheckTask(PtiTasker tasker) { if (string.IsNullOrWhiteSpace(tasker._id) && string.IsNullOrWhiteSpace(tasker.TaskName)) { return(false); } if (string.IsNullOrWhiteSpace(tasker.ApplicationId)) { return(false); } if (string.IsNullOrWhiteSpace(tasker.RunPath)) { //tasker.RunPath = "./" + tasker.ApplicationId; tasker.RunPath = Path.Combine(Config.Get().AppRunPath, tasker.ApplicationId); } if (string.IsNullOrWhiteSpace(tasker._id)) { tasker._id = MD5Helper.getMd5Hash(tasker.TaskName); } return(true); }
/// <summary> /// 添加一个任务 /// </summary> /// <param name="tasker"></param> /// <param name="app"></param> /// <param name="immediately"></param> public PtiEventer AddTask(PtiTasker tasker, PtiApp app = null, bool immediately = false) { return(EventManager.Get().RegEvent(ptievent => { try { if (app == null) { app = DBManager.Get().Db.GetAppById(tasker.ApplicationId); if (app == null) { return false; } } tasker.RunCmd = app.DefaultRunCmd; var r = this.TaskPool.Where(i => i.PtiTasker._id == tasker._id).FirstOrDefault(); if (r == null) { if (!CheckTask(tasker)) { WriteWarning($"Task {tasker._id}({tasker.TaskName}) 添加失败,任务参数不正确!"); return false; } //APP改成从APP模块查询获得 PtiRunTask runtask = new PtiRunTask() { PtiTasker = tasker, PtiApp = app }; if (!immediately) { if (runtask.PtiTasker.Schedule != null) { runtask.NextRunDate = Schedule.CalculateDateScheduleFromNow(runtask.PtiTasker.Schedule); } else { runtask.NextRunDate = DateTime.Now; } } else { runtask.NextRunDate = DateTime.Now.AddSeconds(3); } this.TaskPool.Add(runtask); DBManager.Get().SaveTask(tasker);//立即储存 return true; } else { if (!r.PtiTasker.Enable) { r.PtiTasker.Enable = true; } } return true; } catch (Exception e) { WriteError(e.ToString()); return false; } }, PtiEventType.AddTask)); }