- Notifications
You must be signed in to change notification settings - Fork929
feat: add deleted_at field to workspace model#7475
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
added impending_deletion workspace field
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit4baf40aef8ca8c8051c87fe80532b14f8193299d
There are no files selected for viewing
22 changes: 21 additions & 1 deletioncoderd/workspaces.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1169,7 +1169,10 @@ func convertWorkspace( | ||
autostartSchedule = &workspace.AutostartSchedule.String | ||
} | ||
var ( | ||
ttlMillis = convertWorkspaceTTLMillis(workspace.Ttl) | ||
impendingDeletion = calculateImpendingDeletion(workspace, template) | ||
) | ||
return codersdk.Workspace{ | ||
ID: workspace.ID, | ||
CreatedAt: workspace.CreatedAt, | ||
@@ -1188,6 +1191,7 @@ func convertWorkspace( | ||
AutostartSchedule: autostartSchedule, | ||
TTLMillis: ttlMillis, | ||
LastUsedAt: workspace.LastUsedAt, | ||
ImpendingDeletion: impendingDeletion, | ||
Kira-Pilot marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
} | ||
@@ -1200,6 +1204,22 @@ func convertWorkspaceTTLMillis(i sql.NullInt64) *int64 { | ||
return &millis | ||
} | ||
// Calculate the time of the upcoming working deletion, if applicable; otherwise, return an empty time.Time struct. | ||
// Workspaces may have impending deletions if InactivityTTL feature is turned on and the workspace is inactive. | ||
func calculateImpendingDeletion(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()) | ||
) | ||
// 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) { | ||
return time.Time{} | ||
} | ||
return workspace.LastUsedAt.Add(time.Duration(template.InactivityTTL) * time.Nanosecond) | ||
} | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
func validWorkspaceTTLMillis(millis *int64, templateDefault, templateMax time.Duration) (sql.NullInt64, error) { | ||
if templateDefault == 0 && templateMax != 0 || (templateMax > 0 && templateDefault > templateMax) { | ||
templateDefault = templateMax | ||
1 change: 1 addition & 0 deletionscodersdk/workspaces.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssite/src/api/typesGenerated.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssite/src/testHelpers/entities.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.