コード例 #1
0
        async Task <OrchestrationExecutionCursor> ExecuteOrchestrationAsync(OrchestrationRuntimeState runtimeState)
        {
            TaskOrchestration taskOrchestration = this.objectManager.GetObject(runtimeState.Name, runtimeState.Version);

            if (taskOrchestration == null)
            {
                throw TraceHelper.TraceExceptionInstance(
                          TraceEventType.Error,
                          "TaskOrchestrationDispatcher-TypeMissing",
                          runtimeState.OrchestrationInstance,
                          new TypeMissingException($"Orchestration not found: ({runtimeState.Name}, {runtimeState.Version})"));
            }

            var dispatchContext = new DispatchMiddlewareContext();

            dispatchContext.SetProperty(runtimeState.OrchestrationInstance);
            dispatchContext.SetProperty(taskOrchestration);
            dispatchContext.SetProperty(runtimeState);

            var executor = new TaskOrchestrationExecutor(runtimeState, taskOrchestration, orchestrationService.EventBehaviourForContinueAsNew);

            IEnumerable <OrchestratorAction> decisions = Enumerable.Empty <OrchestratorAction>();

            await this.dispatchPipeline.RunAsync(dispatchContext, _ =>
            {
                decisions = executor.Execute();
                return(CompletedTask);
            });

            return(new OrchestrationExecutionCursor(runtimeState, taskOrchestration, executor, decisions));
        }
コード例 #2
0
        async Task <IEnumerable <OrchestratorAction> > ExecuteOrchestrationAsync(OrchestrationRuntimeState runtimeState)
        {
            TaskOrchestration taskOrchestration = objectManager.GetObject(runtimeState.Name, runtimeState.Version);

            if (taskOrchestration == null)
            {
                throw TraceHelper.TraceExceptionInstance(
                          TraceEventType.Error,
                          "TaskOrchestrationDispatcher-TypeMissing",
                          runtimeState.OrchestrationInstance,
                          new TypeMissingException($"Orchestration not found: ({runtimeState.Name}, {runtimeState.Version})"));
            }

            var dispatchContext = new DispatchMiddlewareContext();

            dispatchContext.SetProperty(runtimeState.OrchestrationInstance);
            dispatchContext.SetProperty(taskOrchestration);
            dispatchContext.SetProperty(runtimeState);

            IEnumerable <OrchestratorAction> decisions = null;

            await this.dispatchPipeline.RunAsync(dispatchContext, _ =>
            {
                var taskOrchestrationExecutor = new TaskOrchestrationExecutor(runtimeState, taskOrchestration);
                decisions = taskOrchestrationExecutor.Execute();

                return(Task.FromResult(0));
            });

            return(decisions);
        }
コード例 #3
0
 public OrchestrationExecutionCursor(
     OrchestrationRuntimeState state,
     TaskOrchestration orchestration,
     TaskOrchestrationExecutor executor,
     IEnumerable <OrchestratorAction> latestDecisions)
 {
     this.RuntimeState          = state;
     this.TaskOrchestration     = orchestration;
     this.OrchestrationExecutor = executor;
     this.LatestDecisions       = latestDecisions;
 }
コード例 #4
0
        async Task <OrchestrationExecutionCursor> ExecuteOrchestrationAsync(OrchestrationRuntimeState runtimeState, TaskOrchestrationWorkItem workItem)
        {
            // Get the TaskOrchestration implementation. If it's not found, it either means that the developer never
            // registered it (which is an error, and we'll throw for this further down) or it could be that some custom
            // middleware (e.g. out-of-process execution middleware) is intended to implement the orchestration logic.
            TaskOrchestration?taskOrchestration = this.objectManager.GetObject(runtimeState.Name, runtimeState.Version !);

            var dispatchContext = new DispatchMiddlewareContext();

            dispatchContext.SetProperty(runtimeState.OrchestrationInstance);
            dispatchContext.SetProperty(taskOrchestration);
            dispatchContext.SetProperty(runtimeState);
            dispatchContext.SetProperty(workItem);

            TaskOrchestrationExecutor?executor = null;

            await this.dispatchPipeline.RunAsync(dispatchContext, _ =>
            {
                // Check to see if the custom middleware intercepted and substituted the orchestration execution
                // with its own execution behavior, providing us with the end results. If so, we can terminate
                // the dispatch pipeline here.
                var resultFromMiddleware = dispatchContext.GetProperty <OrchestratorExecutionResult>();
                if (resultFromMiddleware != null)
                {
                    return(CompletedTask);
                }

                if (taskOrchestration == null)
                {
                    throw TraceHelper.TraceExceptionInstance(
                        TraceEventType.Error,
                        "TaskOrchestrationDispatcher-TypeMissing",
                        runtimeState.OrchestrationInstance,
                        new TypeMissingException($"Orchestration not found: ({runtimeState.Name}, {runtimeState.Version})"));
                }

                executor = new TaskOrchestrationExecutor(
                    runtimeState,
                    taskOrchestration,
                    this.orchestrationService.EventBehaviourForContinueAsNew,
                    this.errorPropagationMode);
                OrchestratorExecutionResult resultFromOrchestrator = executor.Execute();
                dispatchContext.SetProperty(resultFromOrchestrator);
                return(CompletedTask);
            });

            var result = dispatchContext.GetProperty <OrchestratorExecutionResult>();
            IEnumerable <OrchestratorAction> decisions = result?.Actions ?? Enumerable.Empty <OrchestratorAction>();

            runtimeState.Status = result?.CustomStatus;

            return(new OrchestrationExecutionCursor(runtimeState, taskOrchestration, executor, decisions));
        }