示例#1
0
        private void StartGroup(IGroupEntity group)
        {
            var groupLogger = LoggerFactory.GetGroupLogger(group.Id, group.GroupKey);

            groupLogger.Trace("Starting group");

            GroupStartContext context = new GroupStartContext(group, groupLogger);

            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;
            }

            //todo get group processes and add to queue
            var groupProcesses = GetGroupProcesses(group.GroupKey);

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

            _logger.Trace($"Submitting processes {groupProcesses.Count}");
            SubmitProcesses(groupProcesses, group);
            _logger.Trace($"Submission complete of {groupProcesses.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;
            }

            var nextProcesses = GetNextProcesses(null);

            nextProcesses.ForEach(p =>
            {
                var volumeMessage = new ProcessExecutionContext(LoggerFactory.GetProcessLogger(p.Id, p.ProcessKey), p);
                Bus.Instance.HandleVolumeRequest(volumeMessage);
            });
        }
示例#2
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);
        }