Skip to content

Commit

Permalink
fix runner deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Aug 6, 2024
1 parent b178512 commit e1e1669
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
28 changes: 7 additions & 21 deletions PoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,28 +475,14 @@ private async Task<bool> DeleteRunner(DeleteRunnerTask rt)

try
{
if (runner.Lifecycle.Any(x => x.Status == RunnerStatus.DeletionQueued))
{
runner.IsOnline = false;
runner.Lifecycle.Add(new()
{
Status = RunnerStatus.Deleted,
EventTimeUtc = DateTime.UtcNow,
Event = "Runner already queued for deletion."
});
}
else
await _cc.DeleteRunner(rt.ServerId);
runner.IsOnline = false;
runner.Lifecycle.Add(new()
{

await _cc.DeleteRunner(rt.ServerId);
runner.IsOnline = false;
runner.Lifecycle.Add(new()
{
Status = RunnerStatus.Deleted,
EventTimeUtc = DateTime.UtcNow,
Event = "Runner was successfully deleted from CSP"
});
}
Status = RunnerStatus.Deleted,
EventTimeUtc = DateTime.UtcNow,
Event = "Runner was successfully deleted from CSP"
});
await db.SaveChangesAsync();

return true;
Expand Down
39 changes: 27 additions & 12 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,21 +456,36 @@ await db.Jobs.AddAsync(new Job
}

// record event in DB
jobRunner.Lifecycle.Add(new()
if (jobRunner.Lifecycle.Any(x => x.Status == RunnerStatus.DeletionQueued))
{
Status = RunnerStatus.DeletionQueued,
EventTimeUtc = DateTime.UtcNow,
Event = $"Workflow Job {jobId} in repo {repoName} has completed."
});
jobRunner.IsOnline = false;
jobRunner.Lifecycle.Add(new()
{
Status = RunnerStatus.DeletionQueued,
EventTimeUtc = DateTime.UtcNow,
Event = $"Workflow Job {jobId} in repo {repoName} has completed. Deletion already queued."
});
jobRunner.IsOnline = false;

}
else
{
jobRunner.Lifecycle.Add(new()
{
Status = RunnerStatus.DeletionQueued,
EventTimeUtc = DateTime.UtcNow,
Event = $"Workflow Job {jobId} in repo {repoName} has completed. Deletion queued."
});
jobRunner.IsOnline = false;
// Sent to pool manager to delete
poolMgr.DeleteTasks.Enqueue(new DeleteRunnerTask
{
ServerId = jobRunner.CloudServerId,
RunnerDbId = jobRunner.RunnerId
});
}

await db.SaveChangesAsync();

// Sent to pool manager to delete
poolMgr.DeleteTasks.Enqueue(new DeleteRunnerTask
{
ServerId = jobRunner.CloudServerId,
RunnerDbId = jobRunner.RunnerId
});
ProcessedJobCount.Labels(job.Owner, jobRunner.Size).Inc();

double secondsAlive = (DateTime.UtcNow - jobRunner.CreateTime).TotalSeconds;
Expand Down

0 comments on commit e1e1669

Please sign in to comment.