Skip to content

Commit e36153a

Browse files
update to .Net 9.0 and fix api deserialize
1 parent 6c2f9d5 commit e36153a

File tree

4 files changed

+87
-33
lines changed

4 files changed

+87
-33
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
1+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
22
USER $APP_UID
33
WORKDIR /app
44
EXPOSE 8080
55
EXPOSE 8081
66

7-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
7+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
88
ARG BUILD_CONFIGURATION=Release
99
WORKDIR /src
1010
COPY ["GithubActionsOrchestrator.csproj", "./"]

GitHubApi.cs

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Net.Http.Headers;
22
using System.Text.Json;
3+
using System.Text.Json.Serialization;
34
using GithubActionsOrchestrator.GitHub;
45
using Npgsql.Replication;
56
using Serilog;
@@ -157,7 +158,7 @@ public static async Task<bool> RemoveRunnerFromRepo(string repoName, string orgG
157158

158159
}
159160

160-
public static async Task<GitHubJob> GetJobInfoForOrg(long stuckJobGithubJobId,string repoName, string orgGitHubToken)
161+
public static async Task<GitHubApiWorkflowRun> GetJobInfoForOrg(long stuckJobGithubJobId,string repoName, string orgGitHubToken)
161162
{
162163
using HttpClient client = new();
163164
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github+json"));
@@ -170,15 +171,15 @@ public static async Task<GitHubJob> GetJobInfoForOrg(long stuckJobGithubJobId,st
170171
if(response.IsSuccessStatusCode)
171172
{
172173
string content = await response.Content.ReadAsStringAsync();
173-
GitHubJob responseObject = JsonSerializer.Deserialize<GitHubJob>(content);
174+
GitHubApiWorkflowRun responseObject = JsonSerializer.Deserialize<GitHubApiWorkflowRun>(content);
174175

175176
return responseObject;
176177
}
177178
Log.Warning($"Unable to get GH job info for {repoName}/{stuckJobGithubJobId}: [{response.StatusCode}] {response.ReasonPhrase}");
178179

179180
return null;
180181
}
181-
public static async Task<GitHubJob> GetJobInfoForRepo(long stuckJobGithubJobId,string repoName, string orgGitHubToken)
182+
public static async Task<GitHubApiWorkflowRun> GetJobInfoForRepo(long stuckJobGithubJobId,string repoName, string orgGitHubToken)
182183
{
183184
using HttpClient client = new();
184185
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github+json"));
@@ -191,7 +192,7 @@ public static async Task<GitHubJob> GetJobInfoForRepo(long stuckJobGithubJobId,s
191192
if(response.IsSuccessStatusCode)
192193
{
193194
string content = await response.Content.ReadAsStringAsync();
194-
GitHubJob responseObject = JsonSerializer.Deserialize<GitHubJob>(content);
195+
GitHubApiWorkflowRun responseObject = JsonSerializer.Deserialize<GitHubApiWorkflowRun>(content);
195196

196197
return responseObject;
197198
}
@@ -201,42 +202,95 @@ public static async Task<GitHubJob> GetJobInfoForRepo(long stuckJobGithubJobId,s
201202
}
202203
}
203204

204-
public class GitHubJob
205+
public class GitHubApiWorkflowJob
205206
{
207+
[JsonPropertyName("name")]
208+
public string Name { get; set; }
209+
210+
[JsonPropertyName("status")]
211+
public string Status { get; set; }
212+
213+
[JsonPropertyName("conclusion")]
214+
public string Conclusion { get; set; }
215+
216+
[JsonPropertyName("number")]
217+
public int? Number { get; set; }
218+
219+
[JsonPropertyName("started_at")]
220+
public DateTime? StartedAt { get; set; }
221+
222+
[JsonPropertyName("completed_at")]
223+
public DateTime? CompletedAt { get; set; }
224+
}
206225

207-
public int Id { get; set; }
208-
public int RunId { get; set; }
226+
public class GitHubApiWorkflowRun
227+
{
228+
[JsonPropertyName("id")]
229+
public long? Id { get; set; }
230+
231+
[JsonPropertyName("run_id")]
232+
public long? RunId { get; set; }
233+
234+
[JsonPropertyName("workflow_name")]
235+
public string WorkflowName { get; set; }
236+
237+
[JsonPropertyName("head_branch")]
238+
public string HeadBranch { get; set; }
239+
240+
[JsonPropertyName("run_url")]
209241
public string RunUrl { get; set; }
210-
public int RunAttempt { get; set; }
242+
243+
[JsonPropertyName("run_attempt")]
244+
public int? RunAttempt { get; set; }
245+
246+
[JsonPropertyName("node_id")]
211247
public string NodeId { get; set; }
248+
249+
[JsonPropertyName("head_sha")]
212250
public string HeadSha { get; set; }
251+
252+
[JsonPropertyName("url")]
213253
public string Url { get; set; }
254+
255+
[JsonPropertyName("html_url")]
214256
public string HtmlUrl { get; set; }
257+
258+
[JsonPropertyName("status")]
215259
public string Status { get; set; }
260+
261+
[JsonPropertyName("conclusion")]
216262
public string Conclusion { get; set; }
217-
public DateTime CreatedAt { get; set; }
218-
public DateTime StartedAt { get; set; }
219-
public DateTime? CompletedAt { get; set; } // Nullable
263+
264+
[JsonPropertyName("created_at")]
265+
public DateTime? CreatedAt { get; set; }
266+
267+
[JsonPropertyName("started_at")]
268+
public DateTime? StartedAt { get; set; }
269+
270+
[JsonPropertyName("completed_at")]
271+
public DateTime? CompletedAt { get; set; }
272+
273+
[JsonPropertyName("name")]
220274
public string Name { get; set; }
221-
public List<GitHubJobStep> Steps { get; set; }
275+
276+
[JsonPropertyName("steps")]
277+
public List<GitHubApiWorkflowJob> Steps { get; set; }
278+
279+
[JsonPropertyName("check_run_url")]
222280
public string CheckRunUrl { get; set; }
281+
282+
[JsonPropertyName("labels")]
223283
public List<string> Labels { get; set; }
224-
public int? RunnerId { get; set; } // Nullable
225-
public string RunnerName { get; set; } // Nullable
226-
public int? RunnerGroupId { get; set; } // Nullable
227-
public string RunnerGroupName { get; set; } // Nullable
228-
public string WorkflowName { get; set; } // Nullable
229-
public string HeadBranch { get; set; } // Nullable
230284

231-
}
285+
[JsonPropertyName("runner_id")]
286+
public long? RunnerId { get; set; }
232287

233-
public class GitHubJobStep
234-
{
235-
public string Status { get; set; }
236-
public string Conclusion { get; set; }
237-
public string Name { get; set; }
238-
public int Number { get; set; }
239-
public DateTime? StartedAt { get; set; } // Nullable
240-
public DateTime? CompletedAt { get; set; } // Nullable
241-
}
288+
[JsonPropertyName("runner_name")]
289+
public string RunnerName { get; set; }
242290

291+
[JsonPropertyName("runner_group_id")]
292+
public int? RunnerGroupId { get; set; }
293+
294+
[JsonPropertyName("runner_group_name")]
295+
public string RunnerGroupName { get; set; }
296+
}

GithubActionsOrchestrator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>disable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<InvariantGlobalization>true</InvariantGlobalization>

PoolManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
5959

6060
DateTime crudeTimer = DateTime.UtcNow;
6161
DateTime crudeStatsTimer = DateTime.UtcNow;
62-
int cullMinutes = 5;
62+
int cullMinutes = 1;
6363
int statsSeconds = 10;
6464

6565
while (!stoppingToken.IsCancellationRequested)
@@ -286,7 +286,7 @@ private async Task CheckForStuckJobs(List<GithubTargetConfiguration> targetConfi
286286
}
287287

288288
// check job on github
289-
GitHubJob ghJob = await GitHubApi.GetJobInfoForRepo(stuckJob.GithubJobId, stuckJob.Repository , owner.GitHubToken);
289+
GitHubApiWorkflowRun ghJob = await GitHubApi.GetJobInfoForRepo(stuckJob.GithubJobId, stuckJob.Repository , owner.GitHubToken);
290290
if (ghJob == null || ghJob.Status != "queued")
291291
{
292292
_logger.LogWarning($"job info for {stuckJob.JobId} not found or job not queued anymore on github.");

0 commit comments

Comments
 (0)