private Task RunTask(IActionContext actionContext, TaskDesc taskDesc, GroupInfo groupInfo)
        {
            bool isSubEntryAction = this.IsSubEntryGroup(taskDesc.TaskInfo.Action);

            if (!isSubEntryAction)
            {
                publishValueService.PublishVars(actionContext.Parameters, taskDesc.TaskInfo.Vars);
            }
            IExecuteContext executeContext = CreateExecuteContext(actionContext, taskDesc, isSubEntryAction);

            return(actionExecuterService.Execute(executeContext).ContinueWith((result) =>
            {
                if (result.IsCompleted && result.Exception == null)
                {
                    var executeResult = result.Result;
                    this.PublishResultVars(actionContext, executeResult, taskDesc);
                    PublishGlobalVars(actionContext, executeResult.IsSuccess, taskDesc);
                    List <TaskDesc> nextTasks = GetNextTasks(actionContext, executeResult.IsSuccess, taskDesc, groupInfo);
                    RunTasks(actionContext, nextTasks, groupInfo).Wait();
                }
                else
                {
                    throw WorkflowError.TaskEexcuteError(taskDesc.TaskName, result.Exception);
                }
            }, actionContext.Token, TaskContinuationOptions.None, TaskScheduler.Current));
        }
Esempio n. 2
0
 protected async Task RunStep(IActionContext actionContext, int index, object item, IIdGenService idGenService, IActionExecuterService actionExecuterService)
 {
     _ = actionExecuterService ?? throw new ArgumentNullException(nameof(actionExecuterService));
     _ = actionContext ?? throw new ArgumentNullException(nameof(actionContext));
     _ = idGenService ?? throw new ArgumentNullException(nameof(idGenService));
     IExecuteContext executeContext = this.OnCreateExecuteContext(actionContext, idGenService, index, item);
     var             result         = await actionExecuterService.Execute(executeContext);
 }
        public Job Start(JobStartInfo jobStartInfo)
        {
            if (jobStartInfo == null)
            {
                throw new ArgumentNullException(nameof(jobStartInfo));
            }

            lock (locker)
            {
                if (this.currentJobs.Count >= MAX_JOB_COUNT)
                {
                    logger.LogError($"Maximizing jobs limit, total count {this.currentJobs.Count}.");
                    throw Errors.JobCountLimitError(MAX_JOB_COUNT);
                }
                var spy         = this.OnCreateSpy(jobStartInfo);
                var executePath = this.OnCreateExecutePath(jobStartInfo);
                var context     = this.OnCreateExecuteContext(jobStartInfo, executePath, spy.Token);
                var task        = actionExecuterService.Execute(context);
                var jobinfo     = new Job()
                {
                    ExecutionId = executePath.ExecuteId, StartInfo = jobStartInfo, Spy = spy, Task = task
                };
                currentJobs[executePath.ExecuteId] = jobinfo;
                this.logger.LogDebug($"Add jobInfo in engine [{ executePath.ExecuteId}]");
                task.ContinueWith((e) =>
                {
                    if (currentJobs.TryRemove(executePath.ExecuteId, out var job))
                    {
                        this.logger.LogDebug($"Remove jobInfo in engine [{ executePath.ExecuteId}].");
                    }
                    else
                    {
                        this.logger.LogWarning($"Can not remove job info in engine [{ executePath.ExecuteId}].");
                    }
                }, TaskScheduler.Current);
                return(jobinfo);
            }
        }