Skip to content

Commit b44fb71

Browse files
committed
Restore lastActivity logic
1 parent b299aba commit b44fb71

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

components/ws-manager-mk2/service/manager.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func (wsm *WorkspaceManagerServer) DescribeWorkspace(ctx context.Context, req *w
464464
Status: wsm.extractWorkspaceStatus(&ws),
465465
}
466466

467-
lastActivity := ws.Status.LastActivity
467+
lastActivity := getLastActivity(&ws)
468468
if lastActivity != nil {
469469
result.LastActivity = lastActivity.UTC().Format(time.RFC3339Nano)
470470
}
@@ -1483,7 +1483,7 @@ func (wav *workspaceActivityVec) getWorkspaceActivityCounts() (active, notActive
14831483
continue
14841484
}
14851485

1486-
hasActivity := ws.Status.LastActivity != nil
1486+
hasActivity := getLastActivity(&ws) != nil
14871487
if hasActivity {
14881488
active++
14891489
} else {
@@ -1493,3 +1493,21 @@ func (wav *workspaceActivityVec) getWorkspaceActivityCounts() (active, notActive
14931493

14941494
return
14951495
}
1496+
1497+
func getLastActivity(ws *workspacev1.Workspace) *time.Time {
1498+
lastActivity := ws.Status.LastActivity
1499+
if lastActivity != nil {
1500+
return &lastActivity.Time
1501+
}
1502+
1503+
// In case we don't have a record of the workspace's last activity, check for the FirstUserActivity condition
1504+
// to see if the lastActivity got lost on a manager restart.
1505+
if ws.IsConditionTrue(workspacev1.WorkspaceConditionFirstUserActivity) {
1506+
now := time.Now().UTC()
1507+
lastActivityStatus := metav1.NewTime(now)
1508+
return &lastActivityStatus.Time
1509+
}
1510+
1511+
// If the FirstUserActivity condition isn't present we know that the workspace has never had user activity.
1512+
return nil
1513+
}

0 commit comments

Comments
 (0)