-
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.
Reorganize and support recursive simple name resolution for signal re…
…sults (#13)
- Loading branch information
Showing
19 changed files
with
348 additions
and
237 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using PSIBR.Liminality; | ||
|
||
namespace Samples.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class OperationOrchestratorController : ControllerBase | ||
{ | ||
private readonly ILogger<OperationOrchestratorController> _logger; | ||
|
||
public OperationOrchestratorController( | ||
ILogger<OperationOrchestratorController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Post(OperationOrchestrator.Request request, [FromServices] OperationOrchestrator.Repository operationOrchestrationRepository) | ||
{ | ||
var operationOrchestrator = operationOrchestrationRepository.Find(Guid.NewGuid().ToString()); | ||
|
||
var requestResult = await operationOrchestrator.SignalAsync(request); | ||
|
||
if (requestResult.InnerResult is not TransitionedResult transitionResult | ||
|| transitionResult.NewState is not OperationOrchestrator.Requesting.Requested) | ||
|
||
{ | ||
return Problem(statusCode: 500); | ||
} | ||
|
||
var startResult = await operationOrchestrator.SignalAsync(new OperationOrchestrator.Start()); | ||
|
||
if (startResult.InnerResult is not TransitionedResult transitionResult2 | ||
|| transitionResult2.NewState is not OperationOrchestrator.InProgress) | ||
{ | ||
return Problem(statusCode: 500); | ||
} | ||
|
||
return Ok(AggregateSignalResult.Combine(requestResult, startResult)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
public class Cancelled { } | ||
|
||
} | ||
} |
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,12 @@ | ||
using PSIBR.Liminality; | ||
|
||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
[Transition<Throw, Failed>] | ||
[Transition<Cancel.Acknowledgement, Cancelled>] | ||
public class Cancelling { } | ||
|
||
} | ||
} |
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,8 @@ | ||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
public class Completed { } | ||
|
||
} | ||
} |
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,11 @@ | ||
using PSIBR.Liminality; | ||
|
||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
[Transition<Request, Requesting>] | ||
public class Created { } | ||
|
||
} | ||
} |
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,8 @@ | ||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
public class Failed { } | ||
|
||
} | ||
} |
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,29 @@ | ||
using PSIBR.Liminality; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
[Transition<Ping, InProgress>] | ||
[Transition<Pause, Pausing>] | ||
[Transition<Complete, Completed>] | ||
[Transition<Cancel, Cancelling>] | ||
[Transition<Throw, Failed>] | ||
public class InProgress | ||
: IAfterEnterHandler<OperationOrchestrator, Start> | ||
{ | ||
public ValueTask<AggregateSignalResult?> AfterEnterAsync(SignalContext<OperationOrchestrator> context, Start signal, CancellationToken cancellationToken = default) | ||
{ | ||
//do work | ||
|
||
// if the work is in the state machine, | ||
// you probably want some extra form of checkpointing and break up long processes. | ||
// Additionally you could add cancellation via a subscription your state store on the Cancelling state's after entry action | ||
return default; | ||
} | ||
} | ||
|
||
} | ||
} |
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,11 @@ | ||
using PSIBR.Liminality; | ||
|
||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
[Transition<Resume, Requesting.Requested>] | ||
public class Paused { } | ||
|
||
} | ||
} |
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,12 @@ | ||
using PSIBR.Liminality; | ||
|
||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
[Transition<Throw, Failed>] | ||
[Transition<Cancel, Cancelled>] | ||
public class Pausing { } | ||
|
||
} | ||
} |
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,22 @@ | ||
using PSIBR.Liminality; | ||
|
||
namespace Samples | ||
{ | ||
public partial class OperationOrchestrator | ||
{ | ||
public class Repository | ||
{ | ||
private readonly LiminalEngine _engine; | ||
private readonly StateMachineDefinition<OperationOrchestrator> _definition; | ||
|
||
public Repository(LiminalEngine engine, StateMachineDefinition<OperationOrchestrator> definition) | ||
{ | ||
_engine = engine; | ||
_definition = definition; | ||
} | ||
|
||
public OperationOrchestrator Find(string orchestrationId) => new(_engine, _definition, orchestrationId); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.