internal DurableController(
     DurableFunctionInfo durableDurableFunctionInfo,
     IPowerShellServices powerShellServices,
     IOrchestrationInvoker orchestrationInvoker)
 {
     _durableFunctionInfo  = durableDurableFunctionInfo;
     _powerShellServices   = powerShellServices;
     _orchestrationInvoker = orchestrationInvoker;
 }
Ejemplo n.º 2
0
        public Hashtable Invoke(OrchestrationBindingInfo orchestrationBindingInfo, IPowerShellServices pwsh)
        {
            try
            {
                var outputBuffer = new PSDataCollection <object>();
                var context      = orchestrationBindingInfo.Context;

                // context.History should never be null when initializing CurrentUtcDateTime
                var orchestrationStart = context.History.First(
                    e => e.EventType == HistoryEventType.OrchestratorStarted);
                context.CurrentUtcDateTime = orchestrationStart.Timestamp.ToUniversalTime();

                // Marks the first OrchestratorStarted event as processed
                orchestrationStart.IsProcessed = true;

                var asyncResult = pwsh.BeginInvoke(outputBuffer);

                var(shouldStop, actions) =
                    orchestrationBindingInfo.Context.OrchestrationActionCollector.WaitForActions(asyncResult.AsyncWaitHandle);

                if (shouldStop)
                {
                    // The orchestration function should be stopped and restarted
                    pwsh.StopInvoke();
                    return(CreateOrchestrationResult(isDone: false, actions, output: null, context.CustomStatus));
                }
                else
                {
                    try
                    {
                        // The orchestration function completed
                        pwsh.EndInvoke(asyncResult);
                        var result = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(outputBuffer);
                        return(CreateOrchestrationResult(isDone: true, actions, output: result, context.CustomStatus));
                    }
                    catch (Exception e)
                    {
                        // The orchestrator code has thrown an unhandled exception:
                        // this should be treated as an entire orchestration failure
                        throw new OrchestrationFailureException(actions, context.CustomStatus, e);
                    }
                }
            }
            finally
            {
                pwsh.ClearStreamsAndCommands();
            }
        }