Skip to content

Commit ad12096

Browse files
committed
Remove bad abstraction
1 parent 193c578 commit ad12096

File tree

5 files changed

+9
-75
lines changed

5 files changed

+9
-75
lines changed

coderd/autobuild/lifecycle_executor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sync/atomic"
99
"time"
1010

11+
"github.com/dustin/go-humanize"
1112
"github.com/google/uuid"
1213
"golang.org/x/sync/errgroup"
1314
"golang.org/x/xerrors"
@@ -22,7 +23,6 @@ import (
2223
"github.com/coder/coder/v2/coderd/database/pubsub"
2324
"github.com/coder/coder/v2/coderd/notifications"
2425
"github.com/coder/coder/v2/coderd/schedule"
25-
duration "github.com/coder/coder/v2/coderd/util/time"
2626
"github.com/coder/coder/v2/coderd/wsbuilder"
2727
)
2828

@@ -324,14 +324,15 @@ func (e *Executor) runOnce(t time.Time) Stats {
324324
}
325325
}
326326
if shouldNotifyDormancy {
327+
dormantTime := time.Now().Add(time.Duration(tmpl.TimeTilDormant))
327328
_, err = e.notificationsEnqueuer.Enqueue(
328329
e.ctx,
329330
ws.OwnerID,
330331
notifications.TemplateWorkspaceDormant,
331332
map[string]string{
332333
"name": ws.Name,
333334
"reason": "inactivity exceeded the dormancy threshold",
334-
"timeTilDormant": duration.Humanize(time.Duration(tmpl.TimeTilDormant)),
335+
"timeTilDormant": humanize.Time(dormantTime),
335336
},
336337
"lifecycle_executor",
337338
ws.ID,

coderd/util/time/duration.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

coderd/util/time/duration_test.go

Lines changed: 0 additions & 57 deletions
This file was deleted.

coderd/workspaces.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strconv"
1212
"time"
1313

14+
"github.com/dustin/go-humanize"
1415
"github.com/go-chi/chi/v5"
1516
"github.com/google/uuid"
1617
"golang.org/x/xerrors"
@@ -32,7 +33,6 @@ import (
3233
"github.com/coder/coder/v2/coderd/searchquery"
3334
"github.com/coder/coder/v2/coderd/telemetry"
3435
"github.com/coder/coder/v2/coderd/util/ptr"
35-
duration "github.com/coder/coder/v2/coderd/util/time"
3636
"github.com/coder/coder/v2/coderd/wsbuilder"
3737
"github.com/coder/coder/v2/codersdk"
3838
"github.com/coder/coder/v2/codersdk/agentsdk"
@@ -1056,14 +1056,15 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
10561056
}
10571057

10581058
if initiatorErr == nil && tmplErr == nil {
1059+
dormantTime := time.Now().Add(time.Duration(tmpl.TimeTilDormant))
10591060
_, err = api.NotificationsEnqueuer.Enqueue(
10601061
ctx,
10611062
workspace.OwnerID,
10621063
notifications.TemplateWorkspaceDormant,
10631064
map[string]string{
10641065
"name": workspace.Name,
10651066
"reason": "a " + initiator.Username + " request",
1066-
"timeTilDormant": duration.Humanize(time.Duration(tmpl.TimeTilDormant)),
1067+
"timeTilDormant": humanize.Time(dormantTime),
10671068
},
10681069
"api",
10691070
workspace.ID,

enterprise/coderd/schedule/template.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"cdr.dev/slog"
1010

11+
"github.com/dustin/go-humanize"
1112
"github.com/google/uuid"
1213
"go.opentelemetry.io/otel/attribute"
1314
"go.opentelemetry.io/otel/trace"
@@ -19,7 +20,6 @@ import (
1920
"github.com/coder/coder/v2/coderd/notifications"
2021
agpl "github.com/coder/coder/v2/coderd/schedule"
2122
"github.com/coder/coder/v2/coderd/tracing"
22-
duration "github.com/coder/coder/v2/coderd/util/time"
2323
"github.com/coder/coder/v2/codersdk"
2424
)
2525

@@ -206,14 +206,15 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
206206
}
207207

208208
for _, ws := range markedForDeletion {
209+
dormantTime := time.Now().Add(opts.TimeTilDormantAutoDelete)
209210
_, err = s.enqueuer.Enqueue(
210211
ctx,
211212
ws.OwnerID,
212213
notifications.TemplateWorkspaceMarkedForDeletion,
213214
map[string]string{
214215
"name": ws.Name,
215216
"reason": "an update to the template's dormancy",
216-
"timeTilDormant": duration.Humanize(opts.TimeTilDormantAutoDelete),
217+
"timeTilDormant": humanize.Time(dormantTime),
217218
},
218219
"scheduletemplate",
219220
// Associate this notification with all the related entities.

0 commit comments

Comments
 (0)