Skip to content

Commit e495fba

Browse files
Drain doctor-fix queued publishes
Co-authored-by: Andrew <andrewxhill@gmail.com>
1 parent 8bb6075 commit e495fba

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

internal/app/repo.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ func runDoctorFix(ctx context.Context, engine git.Engine, cfg policy.File, lockM
11061106
var applied []string
11071107
var skipped []string
11081108
protectedWorktreeCleanForPublish := false
1109+
queuedProtectedTipPublish := false
11091110

11101111
staleLocks, err := lockManager.InspectStale(time.Hour)
11111112
if err != nil {
@@ -1271,11 +1272,31 @@ func runDoctorFix(ctx context.Context, engine git.Engine, cfg policy.File, lockM
12711272
}
12721273
if created {
12731274
applied = append(applied, fmt.Sprintf("queued publish request %d for protected tip %s", request.ID, protectedSHA))
1275+
queuedProtectedTipPublish = true
12741276
}
12751277
}
12761278
}
12771279
}
12781280
}
1281+
1282+
if queuedProtectedTipPublish {
1283+
publishLease, err := lockManager.Acquire(state.PublishLock, "doctor-fix")
1284+
if err == nil {
1285+
result, processErr := processPublishRequest(ctx, store, repoRecord, cfg, publishLease)
1286+
releaseErr := publishLease.Release()
1287+
if processErr != nil {
1288+
return nil, nil, processErr
1289+
}
1290+
if releaseErr != nil {
1291+
return nil, nil, releaseErr
1292+
}
1293+
applied = append(applied, result)
1294+
} else if errors.Is(err, state.ErrLockHeld) {
1295+
skipped = append(skipped, "left queued publish in place because the publish worker is already active")
1296+
} else {
1297+
return nil, nil, err
1298+
}
1299+
}
12791300
return applied, skipped, nil
12801301
}
12811302

internal/app/repo_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,8 @@ func TestDoctorFixAbortsProtectedMergeState(t *testing.T) {
15171517
}
15181518
}
15191519

1520-
func TestDoctorFixQueuesPublishForProtectedTipAheadOfUpstream(t *testing.T) {
1521-
repoRoot, _ := createTestRepoWithRemote(t)
1520+
func TestDoctorFixPublishesProtectedTipAheadOfUpstream(t *testing.T) {
1521+
repoRoot, remoteDir := createTestRepoWithRemote(t)
15221522
initRepoForWorker(t, repoRoot)
15231523

15241524
writeFileAndCommit(t, repoRoot, "ahead.txt", "ahead\n", "main ahead")
@@ -1543,8 +1543,12 @@ func TestDoctorFixQueuesPublishForProtectedTipAheadOfUpstream(t *testing.T) {
15431543
if err != nil {
15441544
t.Fatalf("ListPublishRequests: %v", err)
15451545
}
1546-
if len(requests) != 1 || requests[0].Status != "queued" || requests[0].TargetSHA != head {
1547-
t.Fatalf("expected queued publish for protected tip %q, got %+v", head, requests)
1546+
if len(requests) != 1 || requests[0].Status != "succeeded" || requests[0].TargetSHA != head {
1547+
t.Fatalf("expected succeeded publish for protected tip %q, got %+v", head, requests)
1548+
}
1549+
remoteHead := trimNewline(runTestCommand(t, remoteDir, "git", "rev-parse", "refs/heads/main"))
1550+
if remoteHead != head {
1551+
t.Fatalf("expected remote head %q, got %q", head, remoteHead)
15481552
}
15491553
}
15501554

0 commit comments

Comments
 (0)