fix: fix dormancy notifications (#14029)

This commit is contained in:
Bruno Quaresma
2024-07-29 11:20:04 -03:00
committed by GitHub
parent 22143d3e80
commit 58b810fb0a
12 changed files with 194 additions and 128 deletions
+15 -9
View File
@@ -16,7 +16,6 @@ import (
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/coderd/dormancy"
"github.com/coder/coder/v2/coderd/notifications"
agpl "github.com/coder/coder/v2/coderd/schedule"
"github.com/coder/coder/v2/coderd/tracing"
@@ -205,18 +204,25 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
return database.Template{}, err
}
for _, workspace := range markedForDeletion {
_, err = dormancy.NotifyWorkspaceMarkedForDeletion(
for _, ws := range markedForDeletion {
_, err = s.enqueuer.Enqueue(
ctx,
s.enqueuer,
dormancy.WorkspaceMarkedForDeletionNotification{
Workspace: workspace,
Reason: "template updated to new dormancy policy",
CreatedBy: "scheduletemplate",
ws.OwnerID,
notifications.TemplateWorkspaceMarkedForDeletion,
map[string]string{
"name": ws.Name,
"reason": "an update to the template's dormancy",
"timeTilDormant": opts.TimeTilDormantAutoDelete.String(),
},
"scheduletemplate",
// Associate this notification with all the related entities.
ws.ID,
ws.OwnerID,
ws.TemplateID,
ws.OrganizationID,
)
if err != nil {
s.logger.Warn(ctx, "failed to notify of workspace marked for deletion", slog.Error(err), slog.F("workspace_id", workspace.ID))
s.logger.Warn(ctx, "failed to notify of workspace marked for deletion", slog.Error(err), slog.F("workspace_id", ws.ID))
}
}