Skip to content

Commit 9290720

Browse files
Hub: indicate if command result is awaited
Some commands may be issued on connection and these results are processed as they are encountered instead of being an awaited result elsewhere.
1 parent a057c7f commit 9290720

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

src/Certify.Models/Hub/ManagementHubMessages.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public InstanceCommandRequest(string commandType, KeyValuePair<string, string>[]
9494
/// Command associated value
9595
/// </summary>
9696
public string? Value { get; set; } = string.Empty;
97+
98+
/// <summary>
99+
/// If true we are directly returning this result to a caller
100+
/// </summary>
101+
public bool IsResultAwaited { get; set; }
97102
}
98103

99104
/// <summary>

src/Certify.Server/Certify.Server.Hub.Api/Services/ManagementAPI.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ private async Task SendCommandWithNoResult(string instanceId, InstanceCommandReq
127127
InstanceCommandResult result;
128128
var cmd = new InstanceCommandRequest(commandType, args);
129129

130+
cmd.IsResultAwaited = true;
131+
130132
result = await GetCommandResult(instanceId, cmd);
131133

132134
if (result?.Value != null)

src/Certify.Server/Certify.Server.Hub.Api/SignalR/ManagementHub/InstanceManagementHub.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,29 @@ private async Task ProcessInstanceCommandResult(InstanceCommandResult result, In
248248
// action this message from this instance
249249
_logger?.LogDebug("[ProcessInstanceCommandResult] Received instance command result {instanceId} {cmdType}", instanceId, cmd.CommandType);
250250

251-
if (cmd.CommandType == ManagementHubCommands.GetManagedItems && result.Value != null)
251+
if (!cmd.IsResultAwaited && cmd.CommandType == ManagementHubCommands.GetManagedItems && result.Value != null)
252252
{
253+
// remove awaited command now it's been handled
254+
255+
_stateProvider.RemoveAwaitedCommandRequest(cmd.CommandId);
256+
253257
// got items from an instance
254258
var val = System.Text.Json.JsonSerializer.Deserialize<ManagedInstanceItems>(result.Value, JsonOptions.DefaultJsonSerializerOptions);
255259

256260
_stateProvider.UpdateInstanceItemInfo(instanceId, val!.Items);
257261
}
258-
else if (cmd.CommandType == ManagementHubCommands.GetStatusSummary && result.Value != null)
262+
else if (!cmd.IsResultAwaited && cmd.CommandType == ManagementHubCommands.GetStatusSummary && result.Value != null)
259263
{
264+
// remove awaited command now it's been handled
265+
_stateProvider.RemoveAwaitedCommandRequest(cmd.CommandId);
266+
260267
// got status summary
261268
var val = System.Text.Json.JsonSerializer.Deserialize<StatusSummary>(result.Value, JsonOptions.DefaultJsonSerializerOptions);
262269

263270
_stateProvider.UpdateInstanceStatusSummary(instanceId, val!);
264271
}
265-
else if (result.IsCommandResponse)
272+
else
273+
if (result.IsCommandResponse)
266274
{
267275
_stateProvider.AddAwaitedCommandResult(result);
268276
}

src/Certify.Server/Certify.Server.Hub.Api/SignalR/ManagementHub/InstanceManagementStateProvider.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Concurrent;
1+
using System.Collections.Concurrent;
22
using Certify.Models;
33
using Certify.Models.Hub;
44
using Certify.Models.Reporting;
@@ -17,6 +17,11 @@ public interface IInstanceManagementStateProvider
1717
string? GetInstanceIdForConnection(string connectionId);
1818
List<ManagedInstanceInfo> GetConnectedInstances();
1919
void AddAwaitedCommandRequest(InstanceCommandRequest command);
20+
21+
/// <summary>
22+
/// Remove an awaited command so we don't keep waiting on the result
23+
/// </summary>
24+
/// <param name="commandId"></param>
2025
void RemoveAwaitedCommandRequest(Guid commandId);
2126
InstanceCommandRequest? GetAwaitedCommandRequest(Guid commandId);
2227
void AddAwaitedCommandResult(InstanceCommandResult result);
@@ -228,9 +233,11 @@ public void AddAwaitedCommandResult(InstanceCommandResult result)
228233
}
229234
else
230235
{
231-
_logger.LogDebug("[ConsumeAwaitedCommandResult] Got command result {commandId} {cmdType}..", cmd.CommandId, cmd.CommandType);
236+
_logger.LogDebug("[ConsumeAwaitedCommandResult] Received and consumed command result {commandId} {cmdType}..", cmd.CommandId, cmd.CommandType);
232237
}
233238

239+
RemoveAwaitedCommandRequest(cmd.CommandId);
240+
234241
return cmdResult;
235242
}
236243

@@ -244,7 +251,7 @@ public void RemoveAwaitedCommandRequest(Guid commandId)
244251

245252
if (request != null)
246253
{
247-
_logger.LogDebug("[RemoveAwaitedCommandRequest] Removed command request {commandId} {cmdType}..", request.CommandId, request.CommandType);
254+
_logger.LogDebug("[RemoveAwaitedCommandRequest] Removed awaited command request {commandId} {cmdType}..", request.CommandId, request.CommandType);
248255
}
249256
else
250257
{

0 commit comments

Comments
 (0)