Skip to content

feat: add 'impending deletion' badges to workspaces page #7530

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 15, 2023
Merged
Changes from 1 commit
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
Next Next commit
update deleting logic
  • Loading branch information
Kira-Pilot committed May 11, 2023
commit 0ba53bd2bf6047d3835218dfcb1ede80d817ea1a
17 changes: 11 additions & 6 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,13 +1207,18 @@ func convertWorkspaceTTLMillis(i sql.NullInt64) *int64 {
// Calculate the time of the upcoming workspace deletion, if applicable; otherwise, return nil.
// Workspaces may have impending deletions if InactivityTTL feature is turned on and the workspace is inactive.
func calculateDeletingAt(workspace database.Workspace, template database.Template) *time.Time {
var (
year, month, day = time.Now().Date()
beginningOfToday = time.Date(year, month, day, 0, 0, 0, 0, time.Now().Location())
)
// Workspace is recently inactive but hasn't been inactive for longer than
// the specified template.InactivityTTL threshold

fmt.Println("last used at before now (aka inactive)", workspace.LastUsedAt.Before(time.Now()))
fmt.Println("last used at is more recent than now minus the TTL ", workspace.LastUsedAt.After(time.Now().Add(-time.Duration(template.InactivityTTL)*time.Nanosecond)))

workspaceRecentlyInactive := workspace.LastUsedAt.Before(time.Now()) &&
workspace.LastUsedAt.After(time.Now().Add(-time.Duration(template.InactivityTTL)*time.Nanosecond))

// If InactivityTTL is turned off (set to 0), if the workspace has already been deleted,
// or if the workspace was used sometime within the last day, there is no impending deletion
if template.InactivityTTL == 0 || workspace.Deleted || workspace.LastUsedAt.After(beginningOfToday) {
// or if the workspace is only recently inactive, there is no impending deletion
if template.InactivityTTL == 0 || workspace.Deleted || workspaceRecentlyInactive {
return nil
}

Expand Down