Exemplo n.º 1
0
        public TaskInfo TaskGetInfo(string TaskId)
        {
            lock (_taskServiceLock)
            {
                Task task = Task.Load(TaskId);

                TaskInfo taskInfo = new TaskInfo();
                taskInfo.State = task.State;

                if (task.AssignedTo != null && !String.IsNullOrEmpty(task.AssignedTo.ClusterName))
                {
                    taskInfo.ClusterName = task.AssignedTo.ClusterName;
                    taskInfo.NodesCount  = (uint)task.AssignedTo.Cores.Count(coresOnNode => coresOnNode > 0);
                    taskInfo.CoresCount  = (uint)task.AssignedTo.Cores.Sum();
                    taskInfo.Package     = task.Package.ToString();
                }
                else
                {
                    taskInfo.ClusterName = null;
                    taskInfo.NodesCount  = 0;
                    taskInfo.CoresCount  = 0;
                    taskInfo.Package     = null;
                }

                if (task.Time.Ended.HasValue && task.Time.Started.HasValue)
                {
                    taskInfo.TimeElapsed = (task.Time.Ended.Value - task.Time.Started.Value).TotalSeconds;
                }
                else
                if (task.Time.Started.HasValue)
                {
                    taskInfo.TimeElapsed = (DateTime.Now - task.Time.Started.Value).TotalSeconds;
                }
                else
                {
                    taskInfo.TimeElapsed = 0;
                }

                /*** return output files ***/
                if (task.OutputFiles != null && task.OutputFiles.Length > 0)
                {
                    taskInfo.OutputFiles = new TaskFileDescription[task.OutputFiles.Length];

                    for (int i = 0; i < task.OutputFiles.Length; i++)
                    {
                        taskInfo.OutputFiles[i].fileName  = task.OutputFiles[i].fileName;
                        taskInfo.OutputFiles[i].slotName  = task.OutputFiles[i].slotName;
                        taskInfo.OutputFiles[i].storageId = task.OutputFiles[i].storageId;
                    }
                }
                else
                {
                    taskInfo.OutputFiles = null;
                }

                return(taskInfo);
            }
        }
Exemplo n.º 2
0
        public void TaskComplete(string TaskId)
        {
            lock (_taskServiceLock)
            {
                Log.Info("Задача " + TaskId + ", получено сообщение о завершении");

                const int ATTEMPTS_MAX = 3;
                bool      success      = false;
                var       rnd          = new Random();

                for (int i = 0; i < ATTEMPTS_MAX && !success; i++)
                {
                    try
                    {
                        Task task = Task.Load(TaskId);
                        Log.Stats("T_clust_fin", task.SequenceId, task.TaskId, DateTime.Now);

                        task.Complete();
                        success = true;
                        task.Save();

                        Log.Stats("T_task_fin", task.SequenceId, task.TaskId, DateTime.Now);

                        if (task.SequenceId > 0)
                        {
                            var sequenceService = new SequenceService();
                            sequenceService.StepFinishedCallback(task.SequenceId);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(String.Format(
                                      "Задача {2}, возникло исключение при завершении\n{0}\n{1}", e.Message, e.StackTrace, TaskId
                                      ));
                    }


                    Thread.Sleep(rnd.Next(2 * 1000), 10 * 1000);
                }

                if (!success)
                {
                    TaskFail(TaskId);
                }
            }
        }
Exemplo n.º 3
0
        public void TaskFail(string TaskId)
        {
            lock (_taskServiceLock)
            {
                try
                {
                    Task task = Task.Load(TaskId);
                    task.Fail();
                    task.Save();

                    var sequenceService = new SequenceService();
                    sequenceService.StepFinishedCallback(task.SequenceId);
                }
                catch (Exception e)
                {
                    Log.Error(String.Format(
                                  "Задача {2}, возникло исключение при завершении со статусом Fail\n{0}\n{1}", e.Message, e.StackTrace, TaskId
                                  ));
                }
            }
        }
Exemplo n.º 4
0
        public void TaskAbort(string TaskId)
        {
            lock (_taskServiceLock)
            {
                try
                {
                    Task task = Task.Load(TaskId);
                    task.Abort();
                    task.Save();

                    var sequenceService = new SequenceService();
                    sequenceService.StepFinishedCallback(task.SequenceId);
                }
                catch (Exception e)
                {
                    Log.Error(String.Format(
                                  "Задача {2}, возникло исключение при попытке принудительного завершения\n{0}\n{1}", e.Message, e.StackTrace, TaskId
                                  ));
                }
            }
        }
Exemplo n.º 5
0
        public void TaskRun(string TaskId)
        {
            lock (_taskServiceLock)
            {
                try
                {
                    Task task = Task.Load(TaskId);

                    Log.Stats("T_task_start", task.SequenceId, task.TaskId, DateTime.Now);

                    if (task.AssignedTo == null || String.IsNullOrEmpty(task.AssignedTo.ClusterName))
                    {
                        DateTime timeBefore = DateTime.Now;

                        task.AutoAssign();

                        Log.Stats("T_assign", task.SequenceId, task.TaskId, DateTime.Now - timeBefore);
                    }

                    if (!task.Time.Estimated.HasValue)
                    {
                        throw new Exception("Could not assign task to any cluster!");
                    }

                    task.Run();
                    task.Save();
                }
                catch (Exception e)
                {
                    Log.Error(String.Format(
                                  "Задача {0}, ошибка при запуске: {1}\n{2}",
                                  TaskId, e.Message, e.StackTrace
                                  ));

                    TaskFail(TaskId);
                }
            }
        }