/// <summary> /// Initializes a new instance of the <see cref="AllForOneStrategy"/> class. /// </summary> /// <param name="maxNrOfRetries"> /// The number of times a child actor is allowed to be restarted, negative value means no limit, /// if the limit is exceeded the child actor is stopped. /// </param> /// <param name="withinTimeMilliseconds">duration in milliseconds of the time window for <paramref name="maxNrOfRetries"/>, negative values means no window.</param> /// <param name="decider">The mapping used to translate an <see cref="Exception"/> to a <see cref="Directive"/>.</param> /// <param name="loggingEnabled">If <c>true</c> failures will be logged</param> public AllForOneStrategy(int maxNrOfRetries, int withinTimeMilliseconds, IDecider decider, bool loggingEnabled = true) { _maxNumberOfRetries = maxNrOfRetries; _withinTimeRangeMilliseconds = withinTimeMilliseconds; _decider = decider; LoggingEnabled = loggingEnabled; }
public void MakeDecision_UnhandledDecisionTypeTest([Frozen] IDecider decider, [Frozen] RespondDecisionTaskCompletedRequest respondDecisionTask) { _processor = new SDK.Workflow.WorkflowEventsProcessor(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf); var decisionContext = new WorkflowDecisionContext() { DecisionType = EventType.LambdaFunctionTimedOut }; Assert.Throws <InvalidOperationException>(() => _processor.MakeDecision(decider, decisionContext)); }
public void SetParent(IDecider <string> parent) { if (this.parent != null) { throw new InvalidOperationException("SetParent can only be called once!"); } if (parent == null) { throw new ArgumentNullException(nameof(parent)); } this.parent = parent; }
public void MakeDecision_WorkflowExecutionStartedTest([Frozen] IDecider decider, [Frozen] RespondDecisionTaskCompletedRequest respondDecisionTask) { _processor = new SDK.Workflow.WorkflowEventsProcessor(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf); var decisionContext = new WorkflowDecisionContext() { DecisionType = EventType.WorkflowExecutionStarted }; decider.OnWorkflowExecutionStarted(decisionContext).Returns(info => respondDecisionTask); _decisionCompletedRequest = _processor.MakeDecision(decider, decisionContext); AssertObjectEquals.PropertyValuesAreEqual(_decisionCompletedRequest.Decisions.First(), respondDecisionTask.Decisions.First()); }
public void MakeDecision_NullDeciderTest([Frozen] IDecider decider, [Frozen] RespondDecisionTaskCompletedRequest respondDecisionTask) { _processor = new SDK.Workflow.WorkflowEventsProcessor(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf); var decisionContext = new WorkflowDecisionContext() { DecisionType = EventType.WorkflowExecutionStarted }; _decisionCompletedRequest = _processor.MakeDecision(null, decisionContext); var decision = _decisionCompletedRequest.Decisions.First(); Assert.NotNull(decision); Assert.Equal(DecisionType.FailWorkflowExecution, decision.DecisionType); Assert.NotNull(decision.FailWorkflowExecutionDecisionAttributes); Assert.Equal("Decider not found.", decision.FailWorkflowExecutionDecisionAttributes.Reason); }
private IDecider GetSimpleDecider(Decider decider, Type entityType, IConstraintFactory factory, string tableName, string schema, Func <string, Type, object> unknownParameters) { IDecider deciderObject = factory.CreateDecider(entityType, decider.ContextDriven); decider.Constraints.ForEach(n => deciderObject.AddConstraint(factory.GetConstraint(entityType, n.Constraint.ConstraintIdentifier, (u, t) => { if (u.Equals("tablename", StringComparison.OrdinalIgnoreCase) && t == typeof(string)) { return(tableName); } if (u.Equals("schema", StringComparison.OrdinalIgnoreCase) && t == typeof(string)) { return(schema); } return(unknownParameters(u, t)); }))); return(deciderObject); }
/// <summary> /// Initializes a new instance of the <see cref="AllForOneStrategy"/> class. /// </summary> /// <param name="decider">The mapping used to translate an <see cref="Exception"/> to a <see cref="Directive"/>.</param> public AllForOneStrategy(IDecider decider) : this(-1, -1, decider, true) { //Intentionally left blank }
/// <summary> /// Initializes a new instance of the <see cref="AllForOneStrategy"/> class. /// </summary> /// <param name="maxNrOfRetries"> /// The number of times a child actor is allowed to be restarted, negative value and null means no limit, /// if the limit is exceeded the child actor is stopped. /// </param> /// <param name="withinTimeRange">duration of the time window for maxNrOfRetries, <see cref="Timeout.InfiniteTimeSpan"/> means no window.</param> /// <param name="decider">The mapping used to translate an <see cref="Exception"/> to a <see cref="Directive"/>.</param> public AllForOneStrategy(int?maxNrOfRetries, TimeSpan?withinTimeRange, IDecider decider) : this(maxNrOfRetries.GetValueOrDefault(-1), (int)withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).TotalMilliseconds, decider) { }
/// <summary> /// Initializes a new instance of the <see cref="OneForOneStrategy"/> class. /// </summary> /// <param name="decider">TBD</param> public OneForOneStrategy(IDecider decider) : this(-1, -1, decider, true) { }
public void Run(IDecider decider) { Connect(); this.decider = decider; }
void IConstraint.SetParent(IDecider parent) { SetParent((IDecider <string>)parent); }
/// <summary> /// Applies the fault handling `Directive` (Resume, Restart, Stop) specified in the `Decider` /// to all children when one fails, as opposed to <see cref="AllForOneStrategy" /> that applies /// it only to the child actor that failed. /// </summary> /// <param name="maxNrOfRetries"> /// the number of times a child actor is allowed to be restarted, negative value and null means no limit, /// if the limit is exceeded the child actor is stopped. /// </param> /// <param name="withinTimeRange">duration of the time window for maxNrOfRetries, <see cref="Timeout.InfiniteTimeSpan"/> means no window.</param> /// <param name="decider">mapping from Exception to <see cref="Directive"/></param> public AllForOneStrategy(int?maxNrOfRetries, TimeSpan?withinTimeRange, IDecider decider) : this(maxNrOfRetries.GetValueOrDefault(-1), withinTimeRange.GetValueOrDefault(Timeout.InfiniteTimeSpan).Milliseconds, decider) { //Intentionally left blank }
/// <summary> /// Initializes a new instance of the <see cref="OneForOne"/> class. /// </summary> /// <param name="decider">the decider.</param> public OneForOne(IDecider decider) { this.decider = decider; }
public void SetUp() { decider = new Decider(); }
/// <summary> /// Creates an Amazon RespondDecisionTaskCompletedRequest to notify SWF that decison was made based on decision /// </summary> /// <param name="decider"></param> /// <returns></returns> internal RespondDecisionTaskCompletedRequest MakeDecision(IDecider decider, WorkflowDecisionContext decisionContext) { if (decider == null) { var attributes = new FailWorkflowExecutionDecisionAttributes { Details = "WorkflowId: " + decisionContext.WorkflowId, Reason = "Decider not found." }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = DecisionType.FailWorkflowExecution, FailWorkflowExecutionDecisionAttributes = attributes } } }; return(decisionRequest); } RespondDecisionTaskCompletedRequest decisionCompletedRequest; // Match the context and call the right method to make a decision if (decisionContext.DecisionType == EventType.WorkflowExecutionStarted) { decisionCompletedRequest = decider.OnWorkflowExecutionStarted(decisionContext); } else if (decisionContext.DecisionType == DecisionType.ContinueAsNewWorkflowExecution) { decisionCompletedRequest = decider.OnWorkflowExecutionContinuedAsNew(decisionContext); } else if (decisionContext.DecisionType == EventType.WorkflowExecutionCancelRequested) { decisionCompletedRequest = decider.OnWorkflowExecutionCancelRequested(decisionContext); } else if (decisionContext.DecisionType == EventType.ActivityTaskCompleted) { decisionCompletedRequest = decider.OnActivityTaskCompleted(decisionContext); } else if (decisionContext.DecisionType == EventType.ActivityTaskFailed) { decisionCompletedRequest = decider.OnActivityTaskFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.ActivityTaskTimedOut) { decisionCompletedRequest = decider.OnActivityTaskTimedOut(decisionContext); } else if (decisionContext.DecisionType == EventType.ScheduleActivityTaskFailed) { decisionCompletedRequest = decider.OnScheduleActivityTaskFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionStarted) { decisionCompletedRequest = decider.OnChildWorkflowExecutionStarted(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionCompleted) { decisionCompletedRequest = decider.OnChildWorkflowExecutionCompleted(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionFailed) { decisionCompletedRequest = decider.OnChildWorkflowExecutionFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionTerminated) { decisionCompletedRequest = decider.OnChildWorkflowExecutionTerminated(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionTimedOut) { decisionCompletedRequest = decider.OnChildWorkflowExecutionTimedOut(decisionContext); } else if (decisionContext.DecisionType == EventType.StartChildWorkflowExecutionFailed) { decisionCompletedRequest = decider.OnStartChildWorkflowExecutionFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.TimerStarted) { decisionCompletedRequest = decider.OnTimerStarted(decisionContext); } else if (decisionContext.DecisionType == EventType.TimerFired) { decisionCompletedRequest = decider.OnTimerFired(decisionContext); } else if (decisionContext.DecisionType == EventType.TimerCanceled) { decisionCompletedRequest = decider.OnTimerCanceled(decisionContext); } else if (decisionContext.DecisionType == EventType.StartChildWorkflowExecutionInitiated) { decisionCompletedRequest = decider.OnStartChildWorkflowExecutionInitiated(decisionContext); } else if (decisionContext.DecisionType == EventType.WorkflowExecutionSignaled) { decisionCompletedRequest = decider.OnWorkflowExecutionSignaled(decisionContext); } else if (decisionContext.DecisionType == EventType.WorkflowExecutionCompleted) { decisionCompletedRequest = decider.OnWorkflowExecutionCompleted(decisionContext); } else { throw new InvalidOperationException("Unhandled event type."); } return(decisionCompletedRequest); }