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

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
Kira-Pilot merged 5 commits intomainfromworkspace-impending-deletion/kira-pilot
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from1 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
NextNext commit
added impending_deletion workspace field
  • Loading branch information
@Kira-Pilot
Kira-Pilot committedMay 9, 2023
commit4baf40aef8ca8c8051c87fe80532b14f8193299d
22 changes: 21 additions & 1 deletioncoderd/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1169,7 +1169,10 @@ func convertWorkspace(
autostartSchedule = &workspace.AutostartSchedule.String
}

ttlMillis := convertWorkspaceTTLMillis(workspace.Ttl)
var (
ttlMillis = convertWorkspaceTTLMillis(workspace.Ttl)
impendingDeletion = calculateImpendingDeletion(workspace, template)
)
return codersdk.Workspace{
ID: workspace.ID,
CreatedAt: workspace.CreatedAt,
Expand All@@ -1188,6 +1191,7 @@ func convertWorkspace(
AutostartSchedule: autostartSchedule,
TTLMillis: ttlMillis,
LastUsedAt: workspace.LastUsedAt,
ImpendingDeletion: impendingDeletion,
}
}

Expand All@@ -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)
}

func validWorkspaceTTLMillis(millis *int64, templateDefault, templateMax time.Duration) (sql.NullInt64, error) {
if templateDefault == 0 && templateMax != 0 || (templateMax > 0 && templateDefault > templateMax) {
templateDefault = templateMax
Expand Down
1 change: 1 addition & 0 deletionscodersdk/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,7 @@ type Workspace struct {
AutostartSchedule *string `json:"autostart_schedule,omitempty"`
TTLMillis *int64 `json:"ttl_ms,omitempty"`
LastUsedAt time.Time `json:"last_used_at" format:"date-time"`
ImpendingDeletion time.Time `json:"impending_deletion" format:"date-time"`
}

type WorkspacesRequest struct {
Expand Down
1 change: 1 addition & 0 deletionssite/src/api/typesGenerated.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1104,6 +1104,7 @@ export interface Workspace {
readonly autostart_schedule?: string
readonly ttl_ms?: number
readonly last_used_at: string
readonly impending_deletion: string
}

// From codersdk/workspaceagents.go
Expand Down
1 change: 1 addition & 0 deletionssite/src/testHelpers/entities.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -719,6 +719,7 @@ export const MockWorkspace: TypesGen.Workspace = {
ttl_ms: 2 * 60 * 60 * 1000,
latest_build: MockWorkspaceBuild,
last_used_at: "2022-05-16T15:29:10.302441433Z",
impending_deletion: "0001-01-01T00:00:00Z",
}

export const MockStoppedWorkspace: TypesGen.Workspace = {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp