From 1e3339280b51687fa595bb82cf27648d53328870 Mon Sep 17 00:00:00 2001 From: Julian Rich <123442863+ric394@users.noreply.github.com> Date: Wed, 22 Apr 2026 12:25:53 +1000 Subject: [PATCH] Make it so the close call returns ok even if the pool cannot be closed - also include a message in these instances --- APSIM.POStats.Portal/Controllers/Api.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/APSIM.POStats.Portal/Controllers/Api.cs b/APSIM.POStats.Portal/Controllers/Api.cs index b2a560c..2a2c443 100644 --- a/APSIM.POStats.Portal/Controllers/Api.cs +++ b/APSIM.POStats.Portal/Controllers/Api.cs @@ -124,11 +124,11 @@ public async Task Close(int pullrequestnumber, string commitid) if (statsDb.PullRequestWithCommitExists(pullrequestnumber, commitid)) { Console.WriteLine($"Closing PR \"{pullrequestnumber} with commit {commitid}\""); - + PullRequestDetails pullRequest = new(); try { // Send pass/fail to gitHub - var pullRequest = statsDb.ClosePullRequest(pullrequestnumber); + pullRequest = statsDb.ClosePullRequest(pullrequestnumber); if (PullRequestFunctions.HasExceptionInLogs(pullRequest)) { @@ -143,12 +143,25 @@ public async Task Close(int pullrequestnumber, string commitid) if (string.IsNullOrEmpty(pullRequest.Pool)) throw new Exception("No pool associated with this pull request. Pool is required to close the Azure Batch pool."); - await AzureBatchManager.CloseBatchPoolAsync(pullRequest.Pool); } catch (Exception ex) { return BadRequest(ex.ToString()); } + + // Close the Azure Batch pool + try + { + await AzureBatchManager.CloseBatchPoolAsync(pullRequest.Pool); + } + catch(InvalidOperationException ex) + { + // If we get an exception here, it likely means the pool was + // already closed. + // Log the error, but do not return an error to the user as + // the PR was successfully closed in the database and GitHub. + return Ok($"PR closed, but failed to close Azure Batch pool ({pullRequest.Pool}). Error: {ex}"); + } } else {