-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from the9ball/feat/controller_event
feat: Publish Controller events
- Loading branch information
Showing
5 changed files
with
154 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using DFrame.Controller; | ||
using DFrame.Controller.EventMessage; | ||
using MessagePipe; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace ConsoleController; | ||
|
||
/// <summary> | ||
/// Controller event handler | ||
/// </summary> | ||
internal record class EventHandler(ILogger<EventHandler> logger, ISubscriber<ControllerEventMessage> subscriber) : IHostedService | ||
{ | ||
private IDisposable? eventMessageSubscription = null; | ||
|
||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
var bag = DisposableBag.CreateBuilder(initialCapacity: 1); | ||
subscriber.Subscribe( | ||
eventMessage => | ||
{ | ||
switch (eventMessage.MessageType) | ||
{ | ||
case ControllerEventMessageType.WorkflowStarted: OnWorkflowStarted(eventMessage.ExecutionSummary); break; | ||
case ControllerEventMessageType.SetupCompleted: OnSetupCompleted(eventMessage.ExecutionSummary); break; | ||
case ControllerEventMessageType.ExecuteCompleted: OnExecuteCompleted(eventMessage.ExecutionSummary); break; | ||
case ControllerEventMessageType.TeardownCompleted: OnTeardownCompleted(eventMessage.ExecutionSummary); break; | ||
case ControllerEventMessageType.WorkflowCompleted: OnWorkflowCompleted(eventMessage.ExecutionSummary); break; | ||
default: logger.LogWarning("Unknown message type: {0}", eventMessage.MessageType); break; | ||
} | ||
} | ||
).AddTo(bag); | ||
|
||
eventMessageSubscription = bag.Build(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
Interlocked.Exchange(ref eventMessageSubscription, null)?.Dispose(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
/// <inheritdoc/> | ||
void OnWorkflowStarted(ExecutionSummary executionSummary) | ||
=> logger.LogInformation("{0} : {1} : {2}", nameof(ControllerEventMessageType.WorkflowStarted), executionSummary.Workload, executionSummary.ExecutionId); | ||
|
||
/// <inheritdoc/> | ||
void OnSetupCompleted(ExecutionSummary executionSummary) | ||
=> logger.LogInformation("{0} : {1} : {2}", nameof(ControllerEventMessageType.SetupCompleted), executionSummary.Workload, executionSummary.ExecutionId); | ||
|
||
/// <inheritdoc/> | ||
void OnExecuteCompleted(ExecutionSummary executionSummary) | ||
=> logger.LogInformation("{0} : {1} : {2}", nameof(ControllerEventMessageType.ExecuteCompleted), executionSummary.Workload, executionSummary.ExecutionId); | ||
|
||
/// <inheritdoc/> | ||
void OnTeardownCompleted(ExecutionSummary executionSummary) | ||
=> logger.LogInformation("{0} : {1} : {2}", nameof(ControllerEventMessageType.TeardownCompleted), executionSummary.Workload, executionSummary.ExecutionId); | ||
|
||
/// <inheritdoc/> | ||
void OnWorkflowCompleted(ExecutionSummary executionSummary) | ||
=> logger.LogInformation("{0} : {1} : {2}", nameof(ControllerEventMessageType.WorkflowCompleted), executionSummary.Workload, executionSummary.ExecutionId); | ||
|
||
} |
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,19 @@ | ||
namespace DFrame.Controller.EventMessage; | ||
|
||
/// <summary> | ||
/// Type of <see cref="ControllerEventMessage"/> | ||
/// </summary> | ||
public enum ControllerEventMessageType | ||
{ | ||
WorkflowStarted, | ||
SetupCompleted, | ||
ExecuteCompleted, | ||
TeardownCompleted, | ||
WorkflowCompleted, | ||
} | ||
|
||
/// <summary> | ||
/// Controller event message. | ||
/// </summary> | ||
public record class ControllerEventMessage(ControllerEventMessageType MessageType, ExecutionSummary ExecutionSummary); | ||
|