Skip to content

Commit

Permalink
Fixes #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Oct 26, 2023
1 parent c9e43f6 commit cae03fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SIL.Machine.AspNetCore.Services;
using Microsoft.AspNetCore.DataProtection.KeyManagement.Internal;

namespace SIL.Machine.AspNetCore.Services;

public class ClearMLMonitorService : RecurrentTask
{
Expand Down Expand Up @@ -53,7 +55,9 @@ await _clearMLService.GetTasksByIdAsync(
trainingEngines.Select(e => e.CurrentBuild!.JobId),
cancellationToken
)
).ToDictionary(t => t.Id);
)
.UnionBy(await _clearMLService.GetTasksForCurrentQueueAsync(cancellationToken), t => t.Id)
.ToDictionary(t => t.Id);

Dictionary<string, int> queuePositions = tasks.Values
.Where(t => t.Status is ClearMLTaskStatus.Queued or ClearMLTaskStatus.Created)
Expand Down
11 changes: 11 additions & 0 deletions src/Machine/src/SIL.Machine.AspNetCore/Services/ClearMLService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ public async Task<bool> StopTaskAsync(string id, CancellationToken cancellationT
return updated == 1;
}

public async Task<IReadOnlyList<ClearMLTask>> GetTasksForCurrentQueueAsync(
CancellationToken cancellationToken = default
)
{
var body = new JsonObject { ["name"] = _options.CurrentValue.Queue };
JsonObject? result = await CallAsync("queues", "get_all_ex", body, cancellationToken);
var tasks = (JsonArray?)result?["data"]?["queues"]?[0]?["entries"];
IEnumerable<string> taskIds = tasks?.Select(t => (string)t?["id"]!) ?? new List<string>();
return await GetTasksByIdAsync(taskIds, cancellationToken);
}

public async Task<ClearMLTask?> GetTaskByNameAsync(string name, CancellationToken cancellationToken = default)
{
IReadOnlyList<ClearMLTask> tasks = await GetTasksAsync(new JsonObject { ["name"] = name }, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Task<string> CreateTaskAsync(
Task<bool> EnqueueTaskAsync(string id, CancellationToken cancellationToken = default);
Task<bool> DequeueTaskAsync(string id, CancellationToken cancellationToken = default);
Task<bool> StopTaskAsync(string id, CancellationToken cancellationToken = default);
Task<IReadOnlyList<ClearMLTask>> GetTasksForCurrentQueueAsync(CancellationToken cancellationToken = default);
Task<ClearMLTask?> GetTaskByNameAsync(string name, CancellationToken cancellationToken = default);
Task<IReadOnlyList<ClearMLTask>> GetTasksByIdAsync(
IEnumerable<string> ids,
Expand Down

0 comments on commit cae03fc

Please sign in to comment.