Skip to content

Commit 8aa1ee2

Browse files
committed
refactor from reaper to jobreaper
1 parent 35df01f commit 8aa1ee2

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

cli/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ import (
8787
"github.com/coder/coder/v2/coderd/externalauth"
8888
"github.com/coder/coder/v2/coderd/gitsshkey"
8989
"github.com/coder/coder/v2/coderd/httpmw"
90+
"github.com/coder/coder/v2/coderd/jobreaper"
9091
"github.com/coder/coder/v2/coderd/notifications"
9192
"github.com/coder/coder/v2/coderd/oauthpki"
9293
"github.com/coder/coder/v2/coderd/prometheusmetrics"
9394
"github.com/coder/coder/v2/coderd/prometheusmetrics/insights"
9495
"github.com/coder/coder/v2/coderd/promoauth"
95-
"github.com/coder/coder/v2/coderd/reaper"
9696
"github.com/coder/coder/v2/coderd/schedule"
9797
"github.com/coder/coder/v2/coderd/telemetry"
9898
"github.com/coder/coder/v2/coderd/tracing"
@@ -1129,7 +1129,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
11291129

11301130
hangDetectorTicker := time.NewTicker(vals.JobHangDetectorInterval.Value())
11311131
defer hangDetectorTicker.Stop()
1132-
hangDetector := reaper.New(ctx, options.Database, options.Pubsub, logger, hangDetectorTicker.C)
1132+
hangDetector := jobreaper.New(ctx, options.Database, options.Pubsub, logger, hangDetectorTicker.C)
11331133
hangDetector.Start()
11341134
defer hangDetector.Close()
11351135

coderd/coderdtest/coderdtest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ import (
6868
"github.com/coder/coder/v2/coderd/externalauth"
6969
"github.com/coder/coder/v2/coderd/gitsshkey"
7070
"github.com/coder/coder/v2/coderd/httpmw"
71+
"github.com/coder/coder/v2/coderd/jobreaper"
7172
"github.com/coder/coder/v2/coderd/notifications"
7273
"github.com/coder/coder/v2/coderd/notifications/notificationstest"
7374
"github.com/coder/coder/v2/coderd/rbac"
7475
"github.com/coder/coder/v2/coderd/rbac/policy"
75-
"github.com/coder/coder/v2/coderd/reaper"
7676
"github.com/coder/coder/v2/coderd/runtimeconfig"
7777
"github.com/coder/coder/v2/coderd/schedule"
7878
"github.com/coder/coder/v2/coderd/telemetry"
@@ -367,7 +367,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
367367

368368
hangDetectorTicker := time.NewTicker(options.DeploymentValues.JobHangDetectorInterval.Value())
369369
defer hangDetectorTicker.Stop()
370-
hangDetector := reaper.New(ctx, options.Database, options.Pubsub, options.Logger.Named("reaper.detector"), hangDetectorTicker.C)
370+
hangDetector := jobreaper.New(ctx, options.Database, options.Pubsub, options.Logger.Named("reaper.detector"), hangDetectorTicker.C)
371371
hangDetector.Start()
372372
t.Cleanup(hangDetector.Close)
373373

coderd/reaper/detector.go renamed to coderd/jobreaper/detector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package reaper
1+
package jobreaper
22

33
import (
44
"context"

coderd/reaper/detector_test.go renamed to coderd/jobreaper/detector_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package reaper_test
1+
package jobreaper_test
22

33
import (
44
"context"
@@ -20,9 +20,9 @@ import (
2020
"github.com/coder/coder/v2/coderd/database/dbauthz"
2121
"github.com/coder/coder/v2/coderd/database/dbgen"
2222
"github.com/coder/coder/v2/coderd/database/dbtestutil"
23+
"github.com/coder/coder/v2/coderd/jobreaper"
2324
"github.com/coder/coder/v2/coderd/provisionerdserver"
2425
"github.com/coder/coder/v2/coderd/rbac"
25-
"github.com/coder/coder/v2/coderd/reaper"
2626
"github.com/coder/coder/v2/provisionersdk"
2727
"github.com/coder/coder/v2/testutil"
2828
)
@@ -49,10 +49,10 @@ func jobLogMessages(jobType jobType, threshold float64) []string {
4949
// reapParamsFromJob determines the type and threshold for a job being reaped
5050
func reapParamsFromJob(job database.ProvisionerJob) (jobType, float64) {
5151
jobType := hungJobType
52-
threshold := reaper.HungJobDuration.Minutes()
52+
threshold := jobreaper.HungJobDuration.Minutes()
5353
if !job.StartedAt.Valid {
5454
jobType = notStartedJobType
55-
threshold = reaper.NotStartedTimeElapsed.Minutes()
55+
threshold = jobreaper.NotStartedTimeElapsed.Minutes()
5656
}
5757
return jobType, threshold
5858
}
@@ -69,10 +69,10 @@ func TestDetectorNoJobs(t *testing.T) {
6969
db, pubsub = dbtestutil.NewDB(t)
7070
log = testutil.Logger(t)
7171
tickCh = make(chan time.Time)
72-
statsCh = make(chan reaper.Stats)
72+
statsCh = make(chan jobreaper.Stats)
7373
)
7474

75-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
75+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
7676
detector.Start()
7777
tickCh <- time.Now()
7878

@@ -92,7 +92,7 @@ func TestDetectorNoHungJobs(t *testing.T) {
9292
db, pubsub = dbtestutil.NewDB(t)
9393
log = testutil.Logger(t)
9494
tickCh = make(chan time.Time)
95-
statsCh = make(chan reaper.Stats)
95+
statsCh = make(chan jobreaper.Stats)
9696
)
9797

9898
// Insert some jobs that are running and haven't been updated in a while,
@@ -119,7 +119,7 @@ func TestDetectorNoHungJobs(t *testing.T) {
119119
})
120120
}
121121

122-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
122+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
123123
detector.Start()
124124
tickCh <- now
125125

@@ -139,7 +139,7 @@ func TestDetectorHungWorkspaceBuild(t *testing.T) {
139139
db, pubsub = dbtestutil.NewDB(t)
140140
log = testutil.Logger(t)
141141
tickCh = make(chan time.Time)
142-
statsCh = make(chan reaper.Stats)
142+
statsCh = make(chan jobreaper.Stats)
143143
)
144144

145145
var (
@@ -225,7 +225,7 @@ func TestDetectorHungWorkspaceBuild(t *testing.T) {
225225
t.Log("previous job ID: ", previousWorkspaceBuildJob.ID)
226226
t.Log("current job ID: ", currentWorkspaceBuildJob.ID)
227227

228-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
228+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
229229
detector.Start()
230230
tickCh <- now
231231

@@ -261,7 +261,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideState(t *testing.T) {
261261
db, pubsub = dbtestutil.NewDB(t)
262262
log = testutil.Logger(t)
263263
tickCh = make(chan time.Time)
264-
statsCh = make(chan reaper.Stats)
264+
statsCh = make(chan jobreaper.Stats)
265265
)
266266

267267
var (
@@ -348,7 +348,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideState(t *testing.T) {
348348
t.Log("previous job ID: ", previousWorkspaceBuildJob.ID)
349349
t.Log("current job ID: ", currentWorkspaceBuildJob.ID)
350350

351-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
351+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
352352
detector.Start()
353353
tickCh <- now
354354

@@ -384,7 +384,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *testing.T
384384
db, pubsub = dbtestutil.NewDB(t)
385385
log = testutil.Logger(t)
386386
tickCh = make(chan time.Time)
387-
statsCh = make(chan reaper.Stats)
387+
statsCh = make(chan jobreaper.Stats)
388388
)
389389

390390
var (
@@ -441,7 +441,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *testing.T
441441

442442
t.Log("current job ID: ", currentWorkspaceBuildJob.ID)
443443

444-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
444+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
445445
detector.Start()
446446
tickCh <- now
447447

@@ -477,7 +477,7 @@ func TestDetectorNotStartedWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *tes
477477
db, pubsub = dbtestutil.NewDB(t)
478478
log = testutil.Logger(t)
479479
tickCh = make(chan time.Time)
480-
statsCh = make(chan reaper.Stats)
480+
statsCh = make(chan jobreaper.Stats)
481481
)
482482

483483
var (
@@ -533,7 +533,7 @@ func TestDetectorNotStartedWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *tes
533533

534534
t.Log("current job ID: ", currentWorkspaceBuildJob.ID)
535535

536-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
536+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
537537
detector.Start()
538538
tickCh <- now
539539

@@ -571,7 +571,7 @@ func TestDetectorHungOtherJobTypes(t *testing.T) {
571571
db, pubsub = dbtestutil.NewDB(t)
572572
log = testutil.Logger(t)
573573
tickCh = make(chan time.Time)
574-
statsCh = make(chan reaper.Stats)
574+
statsCh = make(chan jobreaper.Stats)
575575
)
576576

577577
var (
@@ -633,7 +633,7 @@ func TestDetectorHungOtherJobTypes(t *testing.T) {
633633
t.Log("template import job ID: ", templateImportJob.ID)
634634
t.Log("template dry-run job ID: ", templateDryRunJob.ID)
635635

636-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
636+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
637637
detector.Start()
638638
tickCh <- now
639639

@@ -675,7 +675,7 @@ func TestDetectorNotStartedOtherJobTypes(t *testing.T) {
675675
db, pubsub = dbtestutil.NewDB(t)
676676
log = testutil.Logger(t)
677677
tickCh = make(chan time.Time)
678-
statsCh = make(chan reaper.Stats)
678+
statsCh = make(chan jobreaper.Stats)
679679
)
680680

681681
var (
@@ -736,7 +736,7 @@ func TestDetectorNotStartedOtherJobTypes(t *testing.T) {
736736
t.Log("template import job ID: ", templateImportJob.ID)
737737
t.Log("template dry-run job ID: ", templateDryRunJob.ID)
738738

739-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
739+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
740740
detector.Start()
741741
tickCh <- now
742742

@@ -782,7 +782,7 @@ func TestDetectorHungCanceledJob(t *testing.T) {
782782
db, pubsub = dbtestutil.NewDB(t)
783783
log = testutil.Logger(t)
784784
tickCh = make(chan time.Time)
785-
statsCh = make(chan reaper.Stats)
785+
statsCh = make(chan jobreaper.Stats)
786786
)
787787

788788
var (
@@ -822,7 +822,7 @@ func TestDetectorHungCanceledJob(t *testing.T) {
822822

823823
t.Log("template import job ID: ", templateImportJob.ID)
824824

825-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
825+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
826826
detector.Start()
827827
tickCh <- now
828828

@@ -884,7 +884,7 @@ func TestDetectorPushesLogs(t *testing.T) {
884884
db, pubsub = dbtestutil.NewDB(t)
885885
log = testutil.Logger(t)
886886
tickCh = make(chan time.Time)
887-
statsCh = make(chan reaper.Stats)
887+
statsCh = make(chan jobreaper.Stats)
888888
)
889889

890890
var (
@@ -937,7 +937,7 @@ func TestDetectorPushesLogs(t *testing.T) {
937937
require.Len(t, logs, 10)
938938
}
939939

940-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
940+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
941941
detector.Start()
942942

943943
// Create pubsub subscription to listen for new log events.
@@ -1004,15 +1004,15 @@ func TestDetectorMaxJobsPerRun(t *testing.T) {
10041004
db, pubsub = dbtestutil.NewDB(t)
10051005
log = testutil.Logger(t)
10061006
tickCh = make(chan time.Time)
1007-
statsCh = make(chan reaper.Stats)
1007+
statsCh = make(chan jobreaper.Stats)
10081008
org = dbgen.Organization(t, db, database.Organization{})
10091009
user = dbgen.User(t, db, database.User{})
10101010
file = dbgen.File(t, db, database.File{})
10111011
)
10121012

10131013
// Create MaxJobsPerRun + 1 hung jobs.
10141014
now := time.Now()
1015-
for i := 0; i < reaper.MaxJobsPerRun+1; i++ {
1015+
for i := 0; i < jobreaper.MaxJobsPerRun+1; i++ {
10161016
pj := dbgen.ProvisionerJob(t, db, pubsub, database.ProvisionerJob{
10171017
CreatedAt: now.Add(-time.Hour),
10181018
UpdatedAt: now.Add(-time.Hour),
@@ -1035,14 +1035,14 @@ func TestDetectorMaxJobsPerRun(t *testing.T) {
10351035
})
10361036
}
10371037

1038-
detector := reaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
1038+
detector := jobreaper.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
10391039
detector.Start()
10401040
tickCh <- now
10411041

10421042
// Make sure that only MaxJobsPerRun jobs are terminated.
10431043
stats := <-statsCh
10441044
require.NoError(t, stats.Error)
1045-
require.Len(t, stats.TerminatedJobIDs, reaper.MaxJobsPerRun)
1045+
require.Len(t, stats.TerminatedJobIDs, jobreaper.MaxJobsPerRun)
10461046

10471047
// Run the detector again and make sure that only the remaining job is
10481048
// terminated.

provisioner/terraform/serve.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"cdr.dev/slog"
1717

1818
"github.com/coder/coder/v2/coderd/database"
19-
"github.com/coder/coder/v2/coderd/reaper"
19+
"github.com/coder/coder/v2/coderd/jobreaper"
2020
"github.com/coder/coder/v2/provisionersdk"
2121
)
2222

@@ -131,7 +131,7 @@ func Serve(ctx context.Context, options *ServeOptions) error {
131131
options.Tracer = trace.NewNoopTracerProvider().Tracer("noop")
132132
}
133133
if options.ExitTimeout == 0 {
134-
options.ExitTimeout = reaper.HungJobExitTimeout
134+
options.ExitTimeout = jobreaper.HungJobExitTimeout
135135
}
136136
return provisionersdk.Serve(ctx, &server{
137137
execMut: &sync.Mutex{},

0 commit comments

Comments
 (0)