示例#1
0
        private void CheckGroupHealth(SubmittedGroup groupDetails, bool refresh = true)
        {
            if (refresh)
            {
                groupDetails.Refresh(_stateManager);
            }

            if (groupDetails.GroupEntity.IsFinished)
            {
                _runningGroups.TryRemove(groupDetails.GroupEntity.Id, out groupDetails);
                _eventAggregator.Broadcast(new ProcessGroupRemovedMessage(groupDetails, this));
            }
            else
            {
                //if (!groupDetails.GroupEntity.IsGenerated)
                //{
                //    HandleNewGroup(groupDetails.GroupEntity.Id);
                //    return;
                //}

                //any process running right now
                var groupProcesses = groupDetails.ProcessEntities;// _stateManager.GetConfiguredGroupProcessKeys(groupDetails.GroupEntity.Id).ToList();

                if (groupProcesses.Any(p => p.IsExecuting()))
                {
                    Logger.Trace($"Group id {groupDetails.GroupEntity.Id} is running");

                    return;
                }

                if (groupProcesses.Any(p => p.IsStopped))
                {
                    Logger.Trace($"Group id {groupDetails.GroupEntity.Id} is stopped");
                    groupDetails.GroupEntity.MarkGroupStatus(CompletionStatus.Stopped, ResultStatus.Error, "Execution stopped. Process stopped", _stateManager);
                    _eventAggregator.Broadcast(new ProcessGroupRemovedMessage(groupDetails, this));
                    return;
                }

                //have any process not yet started
                //var processNotGeneratedYet = groupProcesses.Where(p => p.IsVolumeGenerated == false).ToList();
                //if (processNotGeneratedYet.Count != 0)
                //{
                //    SubmitVolumeRequest(processNotGeneratedYet, groupDetails.GroupEntity);
                //}

                var processesNotStartedYet = groupProcesses.Where(p => (p.IsVolumeGenerated == false || p.StartTime.HasValue == false) && p.Status.Id == CompletionStatus.Pending.Id && p.IsStopped == false).ToList();// && processNotGeneratedYet.Exists(g=>g.Id==p.Id)==false).ToList();
                if (processesNotStartedYet.Count == 0)
                {
                    //group processes completed i.e. no process executing and no to start

                    ResultStatus     status;
                    CompletionStatus completionStatus = CompletionStatus.Finished;
                    if (groupProcesses.Any(p => p.IsStopped))
                    {
                        status           = ResultStatus.Empty;
                        completionStatus = CompletionStatus.Stopped;
                    }
                    else
                    {
                        status = groupProcesses.Any(p => ResultStatus.Error.Id == p.Status.Id)
                            ? ResultStatus.Error
                            : ResultStatus.Success;
                    }
                    groupDetails.GroupEntity.MarkGroupStatus(completionStatus, status, "Execution end", _stateManager);
                    //todo cleanup group
                    _eventAggregator.Broadcast(new ProcessGroupRemovedMessage(groupDetails, this));
                }
                else
                {
                    var process2Start = new List <IReadWritableProcessState>();
                    var rootProcess   = groupProcesses.Where(p => p.ParentId == null).ToList();
                    TraverseInComplete(rootProcess, process2Start, groupProcesses);
                    if (process2Start.Any())
                    {
                        SubmitVolumeRequest(process2Start, groupDetails.GroupEntity);
                    }
                    else
                    {
                        groupDetails.GroupEntity.MarkGroupStatus(CompletionStatus.Stopped, ResultStatus.Invalid, "Execution faulted. No process found", _stateManager);
                        _eventAggregator.Broadcast(new ProcessGroupRemovedMessage(groupDetails, this));
                    }
                }
            }
        }