Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions APSIM.POStats.Portal/Controllers/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ public async Task<IActionResult> 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))
{
Expand All @@ -143,12 +143,25 @@ public async Task<IActionResult> 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
{
Expand Down
Loading