-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed SignalAttribute to SignalEventAttribute. Added support for Wo…
…rkflowRestartFailedEvent
- Loading branch information
1 parent
a877216
commit c978e6e
Showing
15 changed files
with
294 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// /Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root folder for license information. | ||
|
||
using Guflow.Decider; | ||
using NUnit.Framework; | ||
|
||
namespace Guflow.Tests.Decider | ||
{ | ||
[TestFixture] | ||
public class WorkflowRestartFailedEventTests | ||
{ | ||
private WorkflowRestartFailedEvent _failedEvent; | ||
private EventGraphBuilder _builder; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_builder = new EventGraphBuilder(); | ||
_failedEvent = new WorkflowRestartFailedEvent(_builder.WorkflowRestartFailedEventGraph("cause")); | ||
} | ||
|
||
[Test] | ||
public void Populate_properties_from_event_graph() | ||
{ | ||
Assert.That(_failedEvent.Cause, Is.EqualTo("cause")); | ||
} | ||
|
||
[Test] | ||
public void By_default_fails_workflow() | ||
{ | ||
var decisions = _failedEvent.Interpret(new EmptyWorkflow()).Decisions(); | ||
|
||
Assert.That(decisions, Is.EqualTo(new[]{new FailWorkflowDecision("FAILED_TO_RESTART_WORKFLOW", "cause")})); | ||
} | ||
|
||
[Test] | ||
public void Can_return_custom_action() | ||
{ | ||
var decisions = _failedEvent.Interpret(new WorkflowWithCompleteAction("result")).Decisions(); | ||
|
||
Assert.That(decisions, Is.EqualTo(new[] { new CompleteWorkflowDecision("result") })); | ||
} | ||
|
||
[WorkflowDescription("1.0")] | ||
private class EmptyWorkflow : Workflow | ||
{ | ||
} | ||
|
||
[WorkflowDescription("1.0")] | ||
private class WorkflowWithCompleteAction : Workflow | ||
{ | ||
private readonly string _result; | ||
|
||
public WorkflowWithCompleteAction(string result) | ||
{ | ||
_result = result; | ||
} | ||
|
||
[WorkflowEvent(EventName.RestartFailed)] | ||
public WorkflowAction OnError() => CompleteWorkflow(_result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. | ||
using Amazon.SimpleWorkflow.Model; | ||
|
||
namespace Guflow.Decider | ||
{ | ||
// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. | ||
using Amazon.SimpleWorkflow.Model; | ||
|
||
namespace Guflow.Decider | ||
{ | ||
/// <summary> | ||
/// Raised when SWF fails to cancel this workflow. | ||
/// </summary> | ||
public class WorkflowCancellationFailedEvent : WorkflowEvent | ||
{ | ||
private readonly CancelWorkflowExecutionFailedEventAttributes _eventAttributes; | ||
internal WorkflowCancellationFailedEvent(HistoryEvent cancellationFailedEvent) | ||
: base(cancellationFailedEvent.EventId) | ||
{ | ||
_eventAttributes = cancellationFailedEvent.CancelWorkflowExecutionFailedEventAttributes; | ||
} | ||
|
||
public string Cause { get { return _eventAttributes.Cause; } } | ||
|
||
internal override WorkflowAction Interpret(IWorkflow workflow) | ||
{ | ||
return workflow.WorkflowAction(this); | ||
} | ||
|
||
internal override WorkflowAction DefaultAction(IWorkflowDefaultActions defaultActions) | ||
{ | ||
return defaultActions.FailWorkflow("FAILED_TO_CANCEL_WORKFLOW", Cause); | ||
} | ||
} | ||
/// </summary> | ||
public class WorkflowCancellationFailedEvent : WorkflowEvent | ||
{ | ||
private readonly CancelWorkflowExecutionFailedEventAttributes _eventAttributes; | ||
internal WorkflowCancellationFailedEvent(HistoryEvent cancellationFailedEvent) | ||
: base(cancellationFailedEvent.EventId) | ||
{ | ||
_eventAttributes = cancellationFailedEvent.CancelWorkflowExecutionFailedEventAttributes; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the reason on why workflow could not be cancelled. | ||
/// </summary> | ||
public string Cause => _eventAttributes.Cause; | ||
|
||
internal override WorkflowAction Interpret(IWorkflow workflow) | ||
{ | ||
return workflow.WorkflowAction(this); | ||
} | ||
|
||
internal override WorkflowAction DefaultAction(IWorkflowDefaultActions defaultActions) | ||
{ | ||
return defaultActions.FailWorkflow("FAILED_TO_CANCEL_WORKFLOW", Cause); | ||
} | ||
} | ||
} |
69 changes: 36 additions & 33 deletions
69
Guflow/Decider/Cancel/WorkflowCancellationRequestedEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. | ||
using Amazon.SimpleWorkflow.Model; | ||
|
||
namespace Guflow.Decider | ||
{ | ||
// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. | ||
using Amazon.SimpleWorkflow.Model; | ||
|
||
namespace Guflow.Decider | ||
{ | ||
/// <summary> | ||
/// Raised when this workflow as received the request to cancel itself. | ||
/// </summary> | ||
public class WorkflowCancellationRequestedEvent : WorkflowEvent | ||
{ | ||
private readonly WorkflowExecutionCancelRequestedEventAttributes _eventAttributes; | ||
|
||
internal WorkflowCancellationRequestedEvent(HistoryEvent cancellationRequestedEvent) | ||
: base(cancellationRequestedEvent.EventId) | ||
{ | ||
_eventAttributes = cancellationRequestedEvent.WorkflowExecutionCancelRequestedEventAttributes; | ||
} | ||
|
||
public string Cause => _eventAttributes.Cause; | ||
|
||
public string ExternalWorkflowRunid => _eventAttributes.ExternalWorkflowExecution?.RunId; | ||
|
||
public string ExternalWorkflowId => _eventAttributes.ExternalWorkflowExecution?.WorkflowId; | ||
|
||
internal override WorkflowAction Interpret(IWorkflow workflow) | ||
{ | ||
return workflow.WorkflowAction(this); | ||
} | ||
|
||
internal override WorkflowAction DefaultAction(IWorkflowDefaultActions defaultActions) | ||
{ | ||
return defaultActions.CancelWorkflow(Cause); | ||
} | ||
} | ||
/// Raised when this workflow has received the request to cancel itself. | ||
/// </summary> | ||
public class WorkflowCancellationRequestedEvent : WorkflowEvent | ||
{ | ||
private readonly WorkflowExecutionCancelRequestedEventAttributes _eventAttributes; | ||
|
||
internal WorkflowCancellationRequestedEvent(HistoryEvent cancellationRequestedEvent) | ||
: base(cancellationRequestedEvent.EventId) | ||
{ | ||
_eventAttributes = cancellationRequestedEvent.WorkflowExecutionCancelRequestedEventAttributes; | ||
} | ||
|
||
/// <summary> | ||
/// Reason why this cancellation request is generated. | ||
/// </summary> | ||
public string Cause => _eventAttributes.Cause; | ||
|
||
public string ExternalWorkflowRunid => _eventAttributes.ExternalWorkflowExecution?.RunId; | ||
|
||
public string ExternalWorkflowId => _eventAttributes.ExternalWorkflowExecution?.WorkflowId; | ||
|
||
internal override WorkflowAction Interpret(IWorkflow workflow) | ||
{ | ||
return workflow.WorkflowAction(this); | ||
} | ||
|
||
internal override WorkflowAction DefaultAction(IWorkflowDefaultActions defaultActions) | ||
{ | ||
return defaultActions.CancelWorkflow(Cause); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,52 @@ | ||
// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. | ||
namespace Guflow.Decider | ||
{ | ||
// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. | ||
namespace Guflow.Decider | ||
{ | ||
/// <summary> | ||
/// Represent a workflow specific event which can use in <see cref="WorkflowEventAttribute"/>. | ||
/// </summary> | ||
public enum EventName | ||
{ | ||
/// </summary> | ||
public enum EventName | ||
{ | ||
/// <summary> | ||
/// Raised when workflow is started. | ||
/// </summary> | ||
WorkflowStarted, | ||
/// </summary> | ||
WorkflowStarted, | ||
/// <summary> | ||
/// Raised when this workflow has received a signal | ||
/// </summary> | ||
Signal, | ||
/// </summary> | ||
Signal, | ||
/// <summary> | ||
/// Raised when this workflow failed to deliver the signal to other workflow. | ||
/// </summary> | ||
SignalFailed, | ||
/// </summary> | ||
SignalFailed, | ||
/// <summary> | ||
/// Raised when this workflow has received the request to cancel itself. | ||
/// </summary> | ||
CancelRequest, | ||
/// </summary> | ||
CancelRequest, | ||
/// <summary> | ||
/// Raised when this workflow fails to send the cancel request to external workflow. | ||
/// </summary> | ||
CancelRequestFailed, | ||
/// </summary> | ||
CancelRequestFailed, | ||
/// <summary> | ||
/// Raised when SWF fails to process CompleteWorkflow action. | ||
/// </summary> | ||
CompletionFailed, | ||
/// </summary> | ||
CompletionFailed, | ||
/// <summary> | ||
/// Raised when SWF fails to process the FailWorkflow action. | ||
/// </summary> | ||
FailureFailed, | ||
/// </summary> | ||
FailureFailed, | ||
/// <summary> | ||
/// Raised when SWF fails to process the CancelWorkflow action. | ||
/// </summary> | ||
CancellationFailed, | ||
|
||
/// </summary> | ||
CancellationFailed, | ||
|
||
/// <summary> | ||
/// Raised when SWF fails to process RecordMarker action. | ||
/// </summary> | ||
RecordMarkerFailed | ||
} | ||
/// </summary> | ||
RecordMarkerFailed, | ||
|
||
/// <summary> | ||
/// Raised when SWF fails to restart the current workflow. This event can be raised in response to RestartWorkflow action. | ||
/// </summary> | ||
RestartFailed | ||
} | ||
} |
Oops, something went wrong.