summaryrefslogtreecommitdiff
path: root/src/marlin.web/Controllers
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2026-10-27 23:04:59 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2026-10-27 23:04:59 +1000
commitecd5f5d13936dd097b12766cb95a568ad5b073a9 (patch)
treef360b08e656a98faca4f2b9f10dc44602e6ca289 /src/marlin.web/Controllers
parent88ee626cb3686dc176cd7911b073c4e65fa54d34 (diff)
feat: lots of stuff
Diffstat (limited to 'src/marlin.web/Controllers')
-rw-r--r--src/marlin.web/Controllers/Api/DispatchController.cs (renamed from src/marlin.web/Controllers/DispatchController.cs)24
-rw-r--r--src/marlin.web/Controllers/Api/InstanceGrpcService.cs54
-rw-r--r--src/marlin.web/Controllers/JobsController.cs4
3 files changed, 69 insertions, 13 deletions
diff --git a/src/marlin.web/Controllers/DispatchController.cs b/src/marlin.web/Controllers/Api/DispatchController.cs
index a37d5fa..076c4dd 100644
--- a/src/marlin.web/Controllers/DispatchController.cs
+++ b/src/marlin.web/Controllers/Api/DispatchController.cs
@@ -1,15 +1,13 @@
-namespace marlin.web.Controllers;
+namespace marlin.web.Controllers.Api;
-using core.models;
-using core.models.meta;
-using core.util;
-using Data;
+using marlin.core.models;
+using marlin.core.util;
+using marlin.web.Data;
+using marlin.web.Models;
+using marlin.web.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Models;
-using Services;
-using Util;
[Route("api/dispatch")]
[ApiController]
@@ -19,7 +17,7 @@ public class DispatchController(ApplicationDbContext dbContext) : ControllerBase
[HttpPost("handshake")]
public async Task<ActionResult<AgentConfiguration>> Handshake(AgentStatus status, CancellationToken ct)
{
- var agentId = User.RequireAgentId();
+ var agentId = this.User.RequireAgentId();
var agent = await dbContext.Agents
.FirstAsync(x => x.Id == agentId, ct);
@@ -34,11 +32,11 @@ public class DispatchController(ApplicationDbContext dbContext) : ControllerBase
MaxConcurrentJobs: agent.MaxConcurrentJobs
);
}
-
+
[HttpGet("queue")]
public async Task<ActionResult<DispatchJob?>> Queue(CancellationToken ct)
{
- var agentId = User.RequireAgentId();
+ var agentId = this.User.RequireAgentId();
var nextJob = await dbContext
.Jobs
@@ -50,7 +48,7 @@ public class DispatchController(ApplicationDbContext dbContext) : ControllerBase
.FirstOrDefaultAsync(ct);
if (nextJob == null)
- return (DispatchJob?) null;
+ return (DispatchJob?)null;
string claimToken = SecureTokenGenerator.CreateClaimToken();
nextJob.ClaimToken = claimToken;
@@ -66,6 +64,6 @@ public class DispatchController(ApplicationDbContext dbContext) : ControllerBase
Commit: nextJob.Commit.Hash,
Recipe: nextJob.Recipe
);
- }
+ }
}
diff --git a/src/marlin.web/Controllers/Api/InstanceGrpcService.cs b/src/marlin.web/Controllers/Api/InstanceGrpcService.cs
new file mode 100644
index 0000000..fb0af5a
--- /dev/null
+++ b/src/marlin.web/Controllers/Api/InstanceGrpcService.cs
@@ -0,0 +1,54 @@
+namespace marlin.web.Controllers.Api;
+
+using core.contracts;
+using core.models;
+using core.models.plan;
+using Data;
+using Grpc.Core;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Models;
+using ProtoBuf.Grpc;
+using Util;
+
+[Authorize(Policy = "JobScoped")]
+public class InstanceGrpcService(ApplicationDbContext dbContext) : IInstanceService
+{
+ public async Task SendLogEvent(LogEventRequest request, CallContext context = default)
+ {
+ var user = context.ServerCallContext!.GetHttpContext().User;
+ var jobId = user.RequireJobId();
+
+ dbContext.Logs.Add(new LogEventRecord
+ {
+ At = request.At,
+ Message = request.Message,
+ Error = request.Error,
+ StepId = request.StepId,
+ JobId = jobId
+ });
+
+ await dbContext.SaveChangesAsync(context.CancellationToken);
+ }
+
+ public async Task SendStatusUpdate(StatusUpdateRequest request, CallContext context = default)
+ {
+ var user = context.ServerCallContext!.GetHttpContext().User;
+ var jobId = user.RequireJobId();
+
+ var job = await dbContext.Jobs
+ .FirstAsync(x => x.Id == jobId, context.CancellationToken);
+
+ job.Status = request.Status;
+
+ dbContext.JobStatusUpdates.Add(new JobStatusUpdate
+ {
+ At = DateTime.UtcNow,
+ Status = request.Status,
+ Job = job
+ });
+
+ await dbContext.SaveChangesAsync(context.CancellationToken);
+ }
+}
diff --git a/src/marlin.web/Controllers/JobsController.cs b/src/marlin.web/Controllers/JobsController.cs
index 552b56c..9aaf6eb 100644
--- a/src/marlin.web/Controllers/JobsController.cs
+++ b/src/marlin.web/Controllers/JobsController.cs
@@ -95,6 +95,10 @@ public class JobsController(ApplicationDbContext dbContext) : Controller
.Include(x => x.Agent)
.Include(x => x.Source)
.Include(x => x.StatusUpdates)
+ .Include(x => x.Logs)
+ .Include(x => x.Branch)
+ .Include(x => x.Commit)
+ .AsSplitQuery()
.FirstOrDefaultAsync(x => x.Id == id);
if (job == null)