Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(coderd): humanize duration on notifications#14333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 4 commits intomainfrombq/fix-dormant-notification
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletioncoderd/autobuild/lifecycle_executor.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
"sync/atomic"
"time"

"github.com/dustin/go-humanize"
"github.com/google/uuid"
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"
Expand DownExpand Up@@ -323,14 +324,15 @@ func (e *Executor) runOnce(t time.Time) Stats {
}
}
if shouldNotifyDormancy {
dormantTime := dbtime.Now().Add(time.Duration(tmpl.TimeTilDormant))
_, err = e.notificationsEnqueuer.Enqueue(
e.ctx,
ws.OwnerID,
notifications.TemplateWorkspaceDormant,
map[string]string{
"name": ws.Name,
"reason": "inactivity exceeded the dormancy threshold",
"timeTilDormant":time.Duration(tmpl.TimeTilDormant).String(),
"timeTilDormant":humanize.Time(dormantTime),
},
"lifecycle_executor",
ws.ID,
Expand Down
17 changes: 15 additions & 2 deletionscoderd/notifications/notifications_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -691,7 +691,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
"reason": "breached the template's threshold for inactivity",
"initiator": "autobuild",
"dormancyHours": "24",
"timeTilDormant": "24h",
"timeTilDormant": "24 hours",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A test which includes not such a round number would also be helpful for illustrative purposes.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Added

},
},
},
Expand All@@ -716,7 +716,20 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
"name": "bobby-workspace",
"reason": "template updated to new dormancy policy",
"dormancyHours": "24",
"timeTilDormant": "24h",
"timeTilDormant": "24 hours",
},
},
},
{
name: "TemplateWorkspaceMarkedForDeletionInOneWeek",
id: notifications.TemplateWorkspaceMarkedForDeletion,
payload: types.MessagePayload{
UserName: "bobby",
Labels: map[string]string{
"name": "bobby-workspace",
"reason": "template updated to new dormancy policy",
"dormancyHours": "168", // 168 hours = 7 days = 1 week
"timeTilDormant": "1 week",
},
},
},
Expand Down
4 changes: 3 additions & 1 deletioncoderd/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ import (
"strconv"
"time"

"github.com/dustin/go-humanize"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"golang.org/x/xerrors"
Expand DownExpand Up@@ -1055,14 +1056,15 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
}

if initiatorErr == nil && tmplErr == nil {
dormantTime := dbtime.Now().Add(time.Duration(tmpl.TimeTilDormant))
_, err = api.NotificationsEnqueuer.Enqueue(
ctx,
workspace.OwnerID,
notifications.TemplateWorkspaceDormant,
map[string]string{
"name": workspace.Name,
"reason": "a " + initiator.Username + " request",
"timeTilDormant":time.Duration(tmpl.TimeTilDormant).String(),
"timeTilDormant":humanize.Time(dormantTime),
},
"api",
workspace.ID,
Expand Down
4 changes: 3 additions & 1 deletionenterprise/coderd/schedule/template.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (

"cdr.dev/slog"

"github.com/dustin/go-humanize"
"github.com/google/uuid"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand DownExpand Up@@ -205,14 +206,15 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
}

for _, ws := range markedForDeletion {
dormantTime := dbtime.Now().Add(opts.TimeTilDormantAutoDelete)
_, err = s.enqueuer.Enqueue(
ctx,
ws.OwnerID,
notifications.TemplateWorkspaceMarkedForDeletion,
map[string]string{
"name": ws.Name,
"reason": "an update to the template's dormancy",
"timeTilDormant":opts.TimeTilDormantAutoDelete.String(),
"timeTilDormant":humanize.Time(dormantTime),
},
"scheduletemplate",
// Associate this notification with all the related entities.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp