public static void Main(string[] args) { try { Console.WriteLine("PtilopsisCliServer 0.1"); Console.WriteLine("2019-11-08"); DBManager.Get().Start(); RunnerManager.Get().Start(); TaskManager.Get().Start(); AppManager.Get().Start(); EventManager.Get().Start(); #if DEBUG string myEnvironmentValue = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); if (myEnvironmentValue == "Development") { string path = Path.Combine(Environment.CurrentDirectory.ToString(), "../ptilopsis-web/build"); Console.WriteLine(Directory.GetCurrentDirectory()); FileHelper.CopyDirectory(path, "./ClientApp"); } #endif CreateHostBuilder(args).Build().Run(); } catch (Exception e) { Console.WriteLine("Start Error£¡Message:" + e.ToString()); Thread.Sleep(3000); } }
static void Main(string[] args) { Console.WriteLine("PtilopsisCliServer 0.1"); Console.WriteLine("2019-11-08"); DBManager.Get().Start(); RunnerManager.Get().Start(); TaskManager.Get().Start(); AppManager.Get().Start(); EventManager.Get().Start(); }
public bool?KillTaskById(string id, int timeout = 10000) { var ptiEvent = EventManager.Get().RegEvent(ptievent => { return(RunnerManager.Get().TaskKillById(id)); }, PtiEventType.Default); DateTime TimeOut = DateTime.Now.AddMilliseconds(timeout); while (DateTime.Now < TimeOut) { if (ptiEvent.IsExcuted) { return(ptiEvent.EventResult as bool?); } Thread.Sleep(100); } return(null); }
static void Main(string[] args) { Console.WriteLine("Ptilopsis 0.1"); Console.WriteLine("2019-10-21"); var dbManager = DBManager.Get(); var runnerManager = RunnerManager.Get(); var taskManager = TaskManager.Get(); var appManager = AppManager.Get(); var eventManager = EventManager.Get(); dbManager.Start(); runnerManager.Start(); taskManager.Start(); appManager.Start(); eventManager.Start(); #region 任务计划计算测试 //DateSchedule sch = new DateSchedule(); //Console.WriteLine(sch.CalculateDateScheduleFromNow("*,*,*,1,0")); //Console.WriteLine(sch.CalculateDateScheduleFromNow("*,*,5,1,0")); #endregion #region App解压测试 PtiApp app = new PtiApp() { Name = "Hello Ptilopsis", ZipFile = "main.zip", DefaultRunCmd = "node" }; app.Id = MD5Helper.getMd5Hash(app.Name); appManager.AddApp(app); //PtiApp app2 = new PtiApp() //{ // Name = "EchoTest", // DefaultRunCmd = "echo" //}; //app2.Id = MD5Helper.getMd5Hash(app.Name); //appManager.AddApp(app2); foreach (var item in dbManager.GetAllApps()) { Console.WriteLine(item.Name); } #endregion #region TASK测试 //PtiTasker task = new PtiTasker() //{ // ApplicationId=app.Id, // RunArgs="main.py", // TaskName= "Hello Ptilopsis", // _id=Guid.NewGuid().ToString("N") //}; PtiTasker task = new PtiTasker() { ApplicationId = app.Id, RunArgs = "main.js", TaskName = "testNode", _id = Guid.NewGuid().ToString("N") }; var _t = taskManager.AddTask(task); //while (!_t.IsExcuted) //{ // Thread.Sleep(100); //} //Console.WriteLine(_t.EventResult); while (true) { Thread.Sleep(100); } #endregion //#if DEBUG // PtiTester tester = new PtiTester(); // PtiApp app = new PtiApp();//APP 项目目录 // PtiTask task = new PtiTask(); // task.RunPath = "D:\\RunPath"; // task.RunCmd = "python"; // task.RunArgs = "main.py"; // PtiRunner runner = new PtiRunner(task, app); // tester.TestRunner(runner); //#endif // Console.WriteLine("Hello World!"); }
/// <summary> /// 循环遍历所有任务,检查可执行的并且执行 /// </summary> /// <param name="value"></param> /// <returns></returns> public object CheckAllTasksEvent(PtiEventer value) { DateTime now = DateTime.Now; foreach (var runtask in this.TaskPool) { try { //判断是否已经禁用任务,从内存中删除任务 if (!runtask.PtiTasker.Enable) { this.RemoveList.Add(runtask); continue; } //判断任务运行是否已经超时 if (runtask.PtiTasker.TimeOutSeconds > 0) { if ((runtask.LastRunDate - now) >= TimeSpan.FromSeconds(runtask.PtiTasker.TimeOutSeconds)) { if (!RunnerManager.Get().CheckTaskAndKill(runtask.PtiTasker)) { WriteWarning($"Task {runtask.PtiTasker._id}({runtask.PtiTasker.TaskName}) Kill Failure!"); } } } //判断启动时间启动任务 if (now >= runtask.NextRunDate) { if (!RunnerManager.Get().CreateAndStart(runtask)) { WriteWarning($"Task {runtask.PtiTasker._id}({runtask.PtiTasker.TaskName}) Start Failure!"); } //没有任务计划的为一次性任务,执行后标记为失效 if (string.IsNullOrWhiteSpace(runtask.PtiTasker.Schedule)) { runtask.PtiTasker.Enable = false; } else { runtask.NextRunDate = Schedule.CalculateDateScheduleFromNow(runtask.PtiTasker.Schedule); } } } catch (Exception e) { WriteError(e.ToString()); } } foreach (var removetask in this.RemoveList) { //立即更新任务 DBManager.Get().SaveTask(removetask.PtiTasker); //如果任务还在运行 if (RunnerManager.Get().TaskExist(removetask.Runner)) { continue; } //在内存中移除任务 if (!this.TaskPool.Remove(removetask)) { WriteWarning($"Task {removetask.PtiTasker._id}({removetask.PtiTasker.TaskName}) remove failure!"); } } this.RemoveList = new List <PtiRunTask>(); WriteInfo("Check All Tasks Success"); return(true); }