summaryrefslogtreecommitdiff
path: root/src/marlin.web/Controllers/JobsController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/marlin.web/Controllers/JobsController.cs')
-rw-r--r--src/marlin.web/Controllers/JobsController.cs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/marlin.web/Controllers/JobsController.cs b/src/marlin.web/Controllers/JobsController.cs
new file mode 100644
index 0000000..1cfdadb
--- /dev/null
+++ b/src/marlin.web/Controllers/JobsController.cs
@@ -0,0 +1,65 @@
+namespace marlin.web.Controllers;
+
+using core.models;
+using Data;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Util;
+
+[Route("jobs")]
+public class JobsController(ApplicationDbContext dbContext) : Controller
+{
+
+ // list jobs (pending, active, cancelled, success, failed), filter to vcs, filter to recipe
+ public record JobListFilter(JobStatus? Status = null, Guid? Vcs = null, string? Ref = null, string? Recipe = null);
+
+ [HttpGet("list")]
+ public async Task<IActionResult> List([FromQuery] JobListFilter filter, CancellationToken ct)
+ {
+ var results = await dbContext.Jobs
+ .WhereIf(filter.Status != null, x => x.Status == filter.Status)
+ .WhereIf(filter.Vcs != null, x => x.SourceId == filter.Vcs)
+ .WhereIf(filter.Ref != null, x => x.Ref == filter.Ref)
+ .WhereIf(filter.Recipe != null, x => x.Recipe == filter.Recipe)
+ .OrderByDescending(x => x.CreatedAt)
+
+ .Include(x => x.Source)
+ .Include(x => x.Agent)
+ .ToListAsync(ct);
+
+ return this.View(results);
+ }
+
+ [HttpGet("spawn")]
+ public async Task<IActionResult> Spawn()
+ {
+ return this.View();
+ }
+
+ public record JobSpawnRequest(Guid Vcs, string Ref, string Commit, string Recipe);
+
+ [HttpPost("spawn")]
+ public async Task<IActionResult> SpawnPost(JobSpawnRequest request, CancellationToken ct)
+ {
+ Job job = new()
+ {
+ SourceId = request.Vcs,
+ Ref = request.Ref,
+ Commit = request.Commit,
+ Recipe = request.Recipe,
+
+ CreatedAt = DateTime.UtcNow,
+ CreatedReason = "user created",
+ Status = JobStatus.Pending
+ };
+
+ await dbContext.Jobs.AddAsync(job, ct);
+ await dbContext.SaveChangesAsync(ct);
+
+ return this.RedirectToAction("Details", new { id = job.Id });
+ }
+
+ // cancel job
+
+ // details job (recipe, status, agent, target, plan, log, artifacts)
+} \ No newline at end of file