Ejemplo n.º 1
0
        private IReadWritableGroupEntity CreateGroupEntity(int key, List <JobCriteria> criteria, bool isManual,
                                                           string triggeredBy, List <int> processKeys)
        {
            var serializer = _serializersFactory.GetSerializer <JobCriteria>();
            var crit       = serializer.SerializeToString(criteria);

            IReadWritableGroupEntity entity = _entityFactory.CreateGroupEntity();

            //IGroupEntity entity =  _entityFactory.CreateGroupEntity(key, crit, isManual, false, triggeredBy, TaskCompletionStatus.Pending.Name);
            IWritableGroupEntity entityW = entity;

            entityW.Criteria       = crit;
            entityW.GroupKey       = key;
            entityW.IsManual       = isManual;
            entityW.IsResubmission = false;
            entityW.SubmittedBy    = triggeredBy;
            entityW.State          = CompletionStatus.Pending.Name;
            if (processKeys != null)
            {
                entityW.Payload = serializer.SerializeToString(processKeys);
            }
            //IGroupEntity g = entity;

            var entity2 = _stateManager.CreateGroupEntity(entity);

            return(entity2);
        }
Ejemplo n.º 2
0
        void CheckSyncGroup(IReadWritableGroupEntity groupEntity)
        {
            List <IReadWritableProcessState>
            processes = _stateManager.GetSubmittedGroupProcesses(groupEntity.Id)
                        .ToList(); //.GetPendingGroupProcess(groupEntity.Id).ToList();
            bool hasAnomaly = false;

            if (!_runningGroups.TryGetValue(groupEntity.Id, out var @group))
            {
                @group = new SubmittedGroup(groupEntity, processes);
                _runningGroups.TryAdd(groupEntity.Id, @group);
                hasAnomaly = true;
            }
            //todo update _runningGroups and check completed/incomplete processes and tasks

            var processRunning = processes.Where(p => p.IsExecuting()).ToList();

            foreach (var running in processRunning)
            {
                var countPendingTasksForProcess = _stateManager.CountPendingTasksForProcess(running.Id);
                if (countPendingTasksForProcess == 0)
                {
                    CheckProcessIdle(running.Id, running.GroupId, true);
                    hasAnomaly = true;
                }
            }

            if (hasAnomaly)
            {
                CheckGroupHealth(@group, false);
            }
        }
Ejemplo n.º 3
0
 public GroupMessage(GroupActions action, IReadWritableGroupEntity entity, List <JobCriteria> criteria, string message = null)
 {
     Action   = action;
     Group    = entity;
     Criteria = criteria;
     Message  = message;
     GroupId  = entity.Id;
 }
Ejemplo n.º 4
0
 public GroupMessage(GroupActions action, IReadWritableGroupEntity entity, List <JobCriteria> criteria, List <int> processKeys)
 {
     Action              = action;
     Group               = entity;
     GroupId             = entity.Id;
     Criteria            = criteria;
     ProcessKeys         = processKeys;
     IsProcessSubmission = true;
 }
Ejemplo n.º 5
0
        public void StopGroup(IReadWritableGroupEntity group, string message)
        {
            _logger.Info($"Stopping group with message {message}");

            _stateManager.MarkGroupStopped(group);
            ////todo mark all pending tasks/processes as stopped
            //group.MarkGroupStatus(CompletionStatus.Stopped, ResultStatus.Empty, message);
            ////publish group stop message
        }
Ejemplo n.º 6
0
        public GroupStartContext(IReadWritableGroupEntity @group, ILogger logger, List <JobCriteria> messageCriteria, Bus bus)
        {
            _groupEntity    = @group;
            _bus            = bus;
            MessageCriteria = messageCriteria;
            Logger          = logger;

            Id             = group.Id;
            GroupKey       = group.GroupKey;
            IsResubmission = group.IsResubmission;
            SubmittedBy    = group.SubmittedBy;
        }
Ejemplo n.º 7
0
 public ProcessExecutionContext(ILogger logger, IReadWritableProcessState processState,
                                IProcessConfiguration configuration, IProcessDataStorage storage,
                                IReadWritableGroupEntity groupDetailsGroupEntity)
 {
     Logger = logger;
     //ProcessState = processState;
     WritableProcessState = processState;
     Configuration        = configuration;
     _storage             = storage;
     GroupEntity          = groupDetailsGroupEntity;
     Criteria             =
         SerializersFactory.Instance.DefaultSerializer.DeserializeFromString <JobCriteria>(processState.Criteria);
 }
Ejemplo n.º 8
0
        public static void MarkGroupStatus(this IReadWritableGroupEntity entity, CompletionStatus completionStatus, ResultStatus result, string reason, IStateManager steManager)
        {
            //IStateManager steManager = Bus.StateManager;
            var isDone = completionStatus.IsDone();

            if (isDone)
            {
                entity.IsFinished = true;
                //entity.CompletedOn = DateTime.UtcNow;
            }
            else
            {
                entity.IsFinished = false;
            }

            //entity.UpdatedOn = DateTime.UtcNow;
            entity.State = result.Name;

            steManager.SaveGroup(entity);
            if (isDone)
            {
                //todo:
            }
        }
Ejemplo n.º 9
0
 public SubmittedGroup(IReadWritableGroupEntity groupEntity, List <IReadWritableProcessState> processEntities)
 {
     GroupEntity     = groupEntity;
     ProcessEntities = processEntities;
 }
Ejemplo n.º 10
0
 public IReadWritableGroupEntity CreateGroupEntity(IReadWritableGroupEntity entity)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public void SaveGroup(IReadWritableGroupEntity group)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
        internal SubmittedGroup CreateProcesses(IReadWritableGroupEntity @group, List <int> processIds,
                                                List <JobCriteria> messageCriteria)
        {
            var groupLogger = _loggerFactory.GetGroupLogger(group.Id, group.GroupKey);

            groupLogger.Trace("Starting group");


            if (processIds == null || processIds.Count == 0)
            {
                _logger.Error("No process found for group");
                StopGroup(@group, "No process found for group");
                return(null);
            }

            var serializer = _serializersFactory.GetSerializer <JobCriteria>();

            GroupStartContext context = new GroupStartContext(group, groupLogger, messageCriteria, Bus);

            var groupSubscribers = _batchEngineSubscribers.GetGroupSubscribers().ToList();

            foreach (var groupSubscriber in groupSubscribers)
            {
                if (groupSubscriber.GroupKey != group.GroupKey)
                {
                    continue;
                }
                context.CurrentSubscriber = groupSubscriber;
                Robustness.Instance.SafeCall(() => { groupSubscriber.OnGroupStarting(context); }, groupLogger);
                context.CurrentSubscriber = null;
            }

            if (context.StopFlag)
            {
                groupLogger.Info("Group stopped by subscriber");
                StopGroup(group, "Group stopped by subscriber");
                return(null);
            }

            //todo get group processes and add to queue
            List <(JobCriteria Criteria, IReadWritableProcessState ProcessState)> process2Submit = new List <(JobCriteria Criteria, IReadWritableProcessState ProcessState)>(); // List<IReadWritableProcessState>();

            List <IReadWritableProcessState> processList = new List <IReadWritableProcessState>();

            foreach (var processId in processIds)
            {
                var process = _entityFactory.CreateProcessEntity();
                process.ProcessId = processId;
                //process
                //IReadWritableProcessState process = erf wer GetKeyProcesses(processKey);
                //IWritableProcessState writableProcess = process;
                process.GroupId = group.Id;

                //process.CorrelationId=Guid.NewGuid();
                processList.Add(process);
            }


            if (processList.Count == 0)
            {
                _logger.Error("No process found for group");
                StopGroup(group, "No process found for group");
                return(null);
            }

            //if (messageCriteria.Count == 1)
            //{
            //    var cta = messageCriteria[0];
            //    process2submit.AddRange(processList.Select(s =>
            //    {
            //        ((IWritableProcessState)s).Criteria = serializer.SerializeToString(cta);
            //        return s;
            //    }));
            //}
            //else
            {
                int groupSeqId = 0;
                foreach (var criteria in messageCriteria)
                {
                    groupSeqId++;
                    foreach (var process in processList)
                    {
                        var p = process.Clone(_entityFactory);
                        p.Criteria          = serializer.SerializeToString(criteria);
                        p.CorrelationId     = Guid.NewGuid();
                        process.CompanyId   = criteria.CompanyId;
                        process.BranchId    = criteria.BranchId;
                        process.SubTenantId = criteria.SubTenantId;
                        p.ProcessingDate    = criteria.ProcessingDate;
                        p.Status            = CompletionStatus.Pending;
                        p.Result            = ResultStatus.Empty;
                        p.GroupSeqId        = groupSeqId;
                        //p.Tag = criteria.Tag; //todo
                        process2Submit.Add((criteria, p));
                    }
                }
            }


            _logger.Trace($"Submitting processes {process2Submit.Count}");
            SubmitProcesses(process2Submit, group);
            _logger.Trace($"Submission complete of {process2Submit.Count} processes");

            foreach (var groupSubscriber in groupSubscribers)
            {
                if (groupSubscriber.GroupKey != group.GroupKey)
                {
                    continue;
                }
                context.CurrentSubscriber = groupSubscriber;
                Robustness.Instance.SafeCall(() => { groupSubscriber.OnGroupSubmitted(context); }, groupLogger);
                context.CurrentSubscriber = null;
            }

            if (context.StopFlag)
            {
                groupLogger.Info("Group stopped by subscriber");
                StopGroup(group, "Group stopped by subscriber");
                return(null);
            }

            //var nextProcesses = GetNextProcesses(null);

            //nextProcesses.ForEach(p =>
            //{
            //    var volumeMessage = new ProcessExecutionContext(BatchLoggerFactory.GetProcessLogger(p.Id, p.ProcessKey), p);
            //    Bus.Instance.HandleVolumeRequest(volumeMessage);
            //});

            SubmittedGroup gGroup = new SubmittedGroup(group, process2Submit.Select(s => s.ProcessState).ToList());

            return(gGroup);
        }
Ejemplo n.º 13
0
 private void SubmitVolumeRequest(IEnumerable <IReadWritableProcessState> processes, IReadWritableGroupEntity groupDetailsGroupEntity)
 {
     try
     {
         foreach (var p in processes)
         {
             var volumeMessage = new ProcessExecutionContext(_loggerFactory.GetProcessLogger(p.Id, p.ProcessId, p.CorrelationId), p, _cacheAside.GetProcessConfiguration(p.ProcessId), _storage, groupDetailsGroupEntity);
             //Bus.HandleVolumeRequest(volumeMessage);
             _volumePipeline.Invoke(volumeMessage);
         }
     }
     catch (Exception e)
     {
         Logger.Error($"Error submitting processes for volume generation. Message {e.Message}", e);
         //process should be marked as error in volume generation, hence no further processing
         _groupsHandler.StopGroup(groupDetailsGroupEntity, $"Error generating volume. Message {e.Message}");
     }
 }
Ejemplo n.º 14
0
 public IReadWritableGroupEntity CreateGroupEntity(IReadWritableGroupEntity entity)
 {
     return(Execute(() => _stateManagerImplementation.CreateGroupEntity(entity)));
 }
Ejemplo n.º 15
0
 public void SaveGroup(IReadWritableGroupEntity @group)
 {
     Execute(() => _stateManagerImplementation.SaveGroup(@group));
 }