Ejemplo n.º 1
0
        public void should_trigger_step_hooks()
        {
            //arrange
            var step1Body = A.Fake <IStepBody>();

            A.CallTo(() => step1Body.RunAsync(A <IStepExecutionContext> .Ignored)).Returns(ExecutionResult.Next());
            WorkflowStep step1 = BuildFakeStep(step1Body);

            Given1StepWorkflow(step1, "Workflow", 1);

            var instance = new WorkflowInstance
            {
                WorkflowDefinitionId = "Workflow",
                Version           = 1,
                Status            = WorkflowStatus.Runnable,
                NextExecution     = 0,
                Id                = "001",
                ExecutionPointers = new List <ExecutionPointer>()
                {
                    new ExecutionPointer()
                    {
                        Active = true, StepId = 0
                    }
                }
            };

            //act
            Subject.Execute(instance);

            //assert
            A.CallTo(() => step1.InitForExecution(A <WorkflowExecutorResult> .Ignored, A <WorkflowDefinition> .Ignored, A <WorkflowInstance> .Ignored, A <ExecutionPointer> .Ignored)).MustHaveHappened();
            A.CallTo(() => step1.BeforeExecute(A <WorkflowExecutorResult> .Ignored, A <IStepExecutionContext> .Ignored, A <ExecutionPointer> .Ignored, A <IStepBody> .Ignored)).MustHaveHappened();
            A.CallTo(() => step1.AfterExecute(A <WorkflowExecutorResult> .Ignored, A <IStepExecutionContext> .Ignored, A <ExecutionResult> .Ignored, A <ExecutionPointer> .Ignored)).MustHaveHappened();
        }
Ejemplo n.º 2
0
        private async Task ExecuteStep(WorkflowInstance workflow, WorkflowStep step, ExecutionPointer pointer, WorkflowExecutorResult wfResult, WorkflowDefinition def)
        {
            using (var scope = _scopeProvider.CreateScope())
            {
                _logger.LogDebug("Starting step {0} on workflow {1}", step.Name, workflow.Id);

                IStepBody body = step.ConstructBody(scope.ServiceProvider);

                if (body == null)
                {
                    _logger.LogError("Unable to construct step body {0}", step.BodyType.ToString());
                    pointer.SleepUntil = _datetimeProvider.Now.ToUniversalTime().Add(_options.ErrorRetryInterval);
                    wfResult.Errors.Add(new ExecutionError()
                    {
                        WorkflowId         = workflow.Id,
                        ExecutionPointerId = pointer.Id,
                        ErrorTime          = _datetimeProvider.Now.ToUniversalTime(),
                        Message            = $"Unable to construct step body {step.BodyType.ToString()}"
                    });
                    return;
                }

                IStepExecutionContext context = new StepExecutionContext()
                {
                    Workflow         = workflow,
                    Step             = step,
                    PersistenceData  = pointer.PersistenceData,
                    ExecutionPointer = pointer,
                    Item             = pointer.ContextItem
                };

                foreach (var input in step.Inputs)
                {
                    input.AssignInput(workflow.Data, body, context);
                }

                switch (step.BeforeExecute(wfResult, context, pointer, body))
                {
                case ExecutionPipelineDirective.Defer:
                    return;

                case ExecutionPipelineDirective.EndWorkflow:
                    workflow.Status       = WorkflowStatus.Complete;
                    workflow.CompleteTime = _datetimeProvider.Now.ToUniversalTime();
                    return;
                }

                var result = await body.RunAsync(context);

                if (result.Proceed)
                {
                    foreach (var output in step.Outputs)
                    {
                        output.AssignOutput(workflow.Data, body, context);
                    }
                }

                _executionResultProcessor.ProcessExecutionResult(workflow, def, pointer, step, result, wfResult);
                step.AfterExecute(wfResult, context, result, pointer);
            }
        }