Skip to content
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