Skip to content

Commit 26f5001

Browse files
committed
use the runOnce time
Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent 1256877 commit 26f5001

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

coderd/autobuild/lifecycle_executor.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010
"sync"
1111
"sync/atomic"
12-
"testing"
1312
"time"
1413

1514
"github.com/dustin/go-humanize"
@@ -138,17 +137,11 @@ func (e *Executor) Run() {
138137
}()
139138
}
140139

141-
func (e *Executor) hasAvailableProvisioners(ctx context.Context, tx database.Store, ws database.Workspace, templateVersionJob database.ProvisionerJob) (bool, error) {
140+
func (e *Executor) hasAvailableProvisioners(ctx context.Context, tx database.Store, t time.Time, ws database.Workspace, templateVersionJob database.ProvisionerJob) (bool, error) {
142141
if e.SkipProvisionerCheck {
143142
return true, nil
144143
}
145144

146-
// Use a shorter stale interval for tests
147-
staleInterval := provisionerdserver.StaleInterval
148-
if testing.Testing() {
149-
staleInterval = TestingStaleInterval
150-
}
151-
152145
// Get eligible provisioner daemons for this workspace's template
153146
provisionerDaemons, err := tx.GetProvisionerDaemonsByOrganization(ctx, database.GetProvisionerDaemonsByOrganizationParams{
154147
OrganizationID: ws.OrganizationID,
@@ -159,11 +152,10 @@ func (e *Executor) hasAvailableProvisioners(ctx context.Context, tx database.Sto
159152
}
160153

161154
// Check if any provisioners are active (not stale)
162-
now := dbtime.Now()
163155
for _, pd := range provisionerDaemons {
164156
if pd.LastSeenAt.Valid {
165-
age := now.Sub(pd.LastSeenAt.Time)
166-
if age <= staleInterval {
157+
age := t.Sub(pd.LastSeenAt.Time)
158+
if age <= provisionerdserver.StaleInterval {
167159
return true, nil
168160
}
169161
}
@@ -327,7 +319,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
327319
}
328320

329321
// Before creating the workspace build, check for available provisioners
330-
hasProvisioners, err := e.hasAvailableProvisioners(e.ctx, tx, ws, templateVersionJob)
322+
hasProvisioners, err := e.hasAvailableProvisioners(e.ctx, tx, t, ws, templateVersionJob)
331323
if err != nil {
332324
return xerrors.Errorf("check provisioner availability: %w", err)
333325
}

0 commit comments

Comments
 (0)