/// <summary> /// 执行Task /// </summary> /// <param name="taskId"></param> /// <param name="parameters"></param> public static void Invoke(string jobId, int taskId, params object[] parameters) { string dataCalculateNode = string.Empty; DataCalculateNodes = new List <string>() { "asfsdf" }; //加锁,保证DataCalculate节点单线程运行 lock (obj) { while (true) { if (DataCalculateNodes.Count > 0) { dataCalculateNode = DataCalculateNodes.FirstOrDefault(); if (!string.IsNullOrEmpty(dataCalculateNode)) { break; } } Thread.Sleep(1000); } } var isSuccess = InvokeDataCalculate(dataCalculateNode, taskId, parameters); if (!isSuccess) { //dataCalculate节点执行方法 //成功的话,取子task,筛选父节点全部执行完毕的子节点加入队列 Expression <Action> expression = () => Invoke(jobId, taskId, null); QueueJob.AddOrUpdate(expression); } }
public static void Invoke(string jobId) { using (MyDbContext context = new MyDbContext()) { context.CycleJob.Add(new Models.CycleJob { JobName = "CycleJob1", CycleCron = "", LastDateTime = DateTime.Now }); context.SaveChanges(); var jobs = context.CycleJob.ToList(); context.SaveChanges(); } //初始化job下所有task状态为未处理 //根据jobId取没有父节点的task,加入待处理队列 int taskId = 0; Expression <Action> expression = () => TaskHandler.Invoke(jobId, taskId, null); QueueJob.AddOrUpdate(expression); }