-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiController.cs
64 lines (53 loc) · 2.23 KB
/
ApiController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using GithubActionsOrchestrator.Database;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace GithubActionsOrchestrator;
[Route("/api")]
public class ApiController : Controller
{
[Route("get-runners")]
public async Task<IResult> GetRunners([FromQuery] int limit = 100, [FromQuery] int offset = 0)
{
var db = new ActionsRunnerContext();
var recentRunners = await db.Runners.Include(x => x.Lifecycle).Include(x => x.Job).OrderByDescending(x => x.RunnerId).Skip(offset).Take(limit).ToListAsync();
return Results.Json(recentRunners);
}
[Route("get-jobs")]
public async Task<IResult> GetJobs([FromQuery] int limit = 100, [FromQuery] int offset = 0)
{
var db = new ActionsRunnerContext();
var recentRunners = await db.Jobs.OrderByDescending(x => x.JobId).Skip(offset).Take(limit).ToListAsync();
return Results.Json(recentRunners);
}
[Route("get-runner/{runnerid}")]
public async Task<IResult> GetRunner(int runnerid)
{
var db = new ActionsRunnerContext();
var runner = await db.Runners.Include(x => x.Lifecycle).FirstOrDefaultAsync(x => x.RunnerId == runnerid);
return Results.Json(runner);
}
[Route("get-job/{jobid}")]
public async Task<IResult> GetJob(int jobid)
{
var db = new ActionsRunnerContext();
var job = await db.Jobs.FirstOrDefaultAsync(x => x.JobId == jobid);
return Results.Json(job);
}
[Route("get-potential-runners/{jobId}")]
public async Task<IResult> GetPotentialRunners(int jobId)
{
var db = new ActionsRunnerContext();
var job = await db.Jobs.FirstOrDefaultAsync(x => x.JobId == jobId);
// get labels
string size = job.RequestedSize;
string owner = job.Owner;
string profile = job.RequestedProfile;
var potentialRunners = db.Runners
.Include(x => x.Lifecycle)
.Where(x => x.Size == size && x.Owner == owner && x.Profile == profile)
.AsEnumerable()
.Where(x => x.LastState == RunnerStatus.Created || x.LastState == RunnerStatus.Provisioned)
.ToList();
return Results.Json(potentialRunners);
}
}