private void ScanRunningTask()
        {
            var runningTasks = DbContext.Task.Where(t => t.IsRunning).ToList();

            foreach (var task in runningTasks)
            {
                var id     = task.Id;
                var status = DbContext.TaskStatus.Where(ts => ts.TaskId == id).OrderByDescending(ts => ts.LastModificationTime).FirstOrDefault();
                if (status != null)
                {
                    if (status.LastModificationTime != null)
                    {
                        if ((DateTime.Now - status.LastModificationTime.Value).TotalSeconds > 3600)
                        {
                            TaskUtil.ExitTask(_nodeAppService, _messageAppService, task, Logger);
                        }
                    }
                    else
                    {
                        if ((DateTime.Now - status.CreationTime).TotalSeconds > 3600)
                        {
                            TaskUtil.ExitTask(_nodeAppService, _messageAppService, task, Logger);
                        }
                    }
                }
            }
            DbContext.SaveChanges();
        }
Ejemplo n.º 2
0
        public void Exit(long taskId)
        {
            var task = DbContext.Task.FirstOrDefault(a => a.Id == taskId);

            if (task == null)
            {
                throw new Exception($"Task {taskId} unfound.");
            }

            // 如果运行的命令还没有被节点消费, 则直接删除运行消息, 减少节点的消耗。
            var runMessage = DbContext.Message.FirstOrDefault(m => m.TaskId == taskId && Core.Entities.Message.RunMessageName == m.Name);

            if (runMessage != null)
            {
                DbContext.Message.Remove(runMessage);
            }

            var cancelMsg = DbContext.Message.FirstOrDefault(a => a.TaskId == task.Id && Core.Entities.Message.CanleMessageName == a.Name);

            if (cancelMsg != null)
            {
                return;
            }

            TaskUtil.ExitTask(_nodeAppService, _messageAppService, task, Logger);

            DbContext.SaveChanges();
        }