Fix operations CI and snapshots
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
@@ -8,6 +9,7 @@ namespace Nexus.Api.Controllers;
|
||||
public class OperationsController(IOperationsService operationsService) : ControllerBase
|
||||
{
|
||||
[HttpGet("snapshot")]
|
||||
[Authorize]
|
||||
public async Task<IResult> GetSnapshot(CancellationToken ct)
|
||||
=> Results.Ok(await operationsService.GetSnapshotAsync(ct));
|
||||
}
|
||||
|
||||
@@ -15,16 +15,13 @@ public sealed class OperationsService(
|
||||
{
|
||||
var runtimeTask = runtime.GetStatusAsync(ct);
|
||||
var agentsTask = agentService.GetAgentsAsync(ct);
|
||||
var projectsTask = projectRepo.GetAllAsync(ct);
|
||||
var tasksTask = taskRepo.GetAllAsync(ct);
|
||||
var activityTask = activityRepo.GetRecentAsync(20, ct);
|
||||
await Task.WhenAll(runtimeTask, agentsTask, projectsTask, tasksTask, activityTask);
|
||||
|
||||
var tasks = tasksTask.Result;
|
||||
var projects = projectsTask.Result;
|
||||
var agents = agentsTask.Result;
|
||||
// Repository calls share the scoped EF Core DbContext and must stay serialized.
|
||||
var projects = await projectRepo.GetAllAsync(ct);
|
||||
var tasks = await taskRepo.GetAllAsync(ct);
|
||||
var activity = await activityRepo.GetRecentAsync(20, ct);
|
||||
var agents = await agentsTask;
|
||||
var completedTasks = tasks.Count(x => x.State == TaskStateHelper.ToStateString(TaskState.Done));
|
||||
var runtimeStatus = runtimeTask.Result;
|
||||
var runtimeStatus = await runtimeTask;
|
||||
|
||||
var lastIncident = tasks
|
||||
.Where(x => x.State == TaskStateHelper.ToStateString(TaskState.Blocked))
|
||||
@@ -56,7 +53,7 @@ public sealed class OperationsService(
|
||||
agents = agents.Select(x => new { x.Id, x.Name, x.Role, x.Status, x.Model }),
|
||||
projects = projects.Select(x => new { x.Id, x.Name, x.Status, x.Progress, x.UpdatedAt }),
|
||||
tasks = tasks.Select(x => new { x.Id, x.Title, x.State, x.Priority, x.ProjectId, x.UpdatedAt }),
|
||||
activity = activityTask.Result.Select(x => new { x.Id, x.Type, x.Message, at = x.CreatedAt })
|
||||
activity = activity.Select(x => new { x.Id, x.Type, x.Message, at = x.CreatedAt })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user