Skip to content

Commit 9b5be48

Browse files
add a created time to fix stuck runners
1 parent f013d18 commit 9b5be48

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

Database/Runner.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@ public class Runner
1616
public ICollection<RunnerLifecycle> Lifecycle { get; set; }
1717
public long CloudServerId { get; set; }
1818

19-
public DateTime CreateTime
19+
public DateTime CreationQueuedTime
2020
{
2121
get
2222
{
2323
return Lifecycle.FirstOrDefault(x => x.Status == RunnerStatus.CreationQueued)!.EventTimeUtc;
2424
}
2525
}
26+
public DateTime CreatedTime
27+
{
28+
get
29+
{
30+
return Lifecycle.FirstOrDefault(x => x.Status == RunnerStatus.Created)!.EventTimeUtc;
31+
}
32+
}
2633

2734
public RunnerStatus LastState
2835
{

PoolManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private async Task CheckForStuckRunners(List<GithubTargetConfiguration> targetCo
151151
{
152152

153153
// check if runner is old enough to be stuck
154-
if (stuckRunner.CreateTime + TimeSpan.FromMinutes(5) > DateTime.UtcNow)
154+
if (stuckRunner.CreatedTime + TimeSpan.FromMinutes(10) > DateTime.UtcNow)
155155
continue;
156156

157157
// Note stuckness in lifecycle and add runner to deletion queue
@@ -453,7 +453,7 @@ private async Task CleanUpRunners(List<GithubTargetConfiguration> targetConfigs)
453453
continue;
454454
}
455455

456-
if (DateTime.UtcNow - runner.CreateTime < TimeSpan.FromMinutes(30))
456+
if (DateTime.UtcNow - runner.CreationQueuedTime < TimeSpan.FromMinutes(30))
457457
{
458458
// VM younger than 30min - not cleaning yet
459459
continue;
@@ -488,7 +488,7 @@ private async Task CleanUpRunners(List<GithubTargetConfiguration> targetConfigs)
488488
continue;
489489
}
490490

491-
if (DateTime.UtcNow - runner.CreateTime < TimeSpan.FromHours(6))
491+
if (DateTime.UtcNow - runner.CreationQueuedTime < TimeSpan.FromHours(6))
492492
{
493493
// VM younger than 6h - not cleaning yet
494494
continue;
@@ -622,7 +622,7 @@ private async Task CleanUpRunners(List<GithubTargetConfiguration> targetConfigs)
622622

623623
foreach (var onlineSrvFromDb in db.Runners.Include(x => x.Lifecycle).Where(x => x.IsOnline))
624624
{
625-
if(onlineSrvFromDb.CreateTime + TimeSpan.FromHours(1) > DateTime.UtcNow ) continue; // Leave young runners alone
625+
if(onlineSrvFromDb.CreationQueuedTime + TimeSpan.FromHours(1) > DateTime.UtcNow ) continue; // Leave young runners alone
626626
if (registeredServerNames.Contains(onlineSrvFromDb.Hostname)) continue;
627627

628628
if(onlineSrvFromDb.LastState == RunnerStatus.DeletionQueued) continue;

Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ await db.Jobs.AddAsync(new Job
535535

536536
ProcessedJobCount.Labels(job.Owner, jobRunner.Size).Inc();
537537

538-
double secondsAlive = (DateTime.UtcNow - jobRunner.CreateTime).TotalSeconds;
538+
double secondsAlive = (DateTime.UtcNow - jobRunner.CreationQueuedTime).TotalSeconds;
539539
TotalMachineTime.Labels(job.Owner, jobRunner.Size).Inc(secondsAlive);
540540

541541
}

0 commit comments

Comments
 (0)