fix monitor desktop unknown recovery

This commit is contained in:
2026-06-22 15:38:06 +08:00
parent 365a41597e
commit 12681105f2
8 changed files with 162 additions and 39 deletions
@@ -612,16 +612,7 @@ func (s *MonitoringService) upsertMonitorDesktopTask(
existingLeaseExpiresAt pgtype.Timestamptz
existingActiveAttempt pgtype.UUID
)
err := tx.QueryRow(ctx, `
SELECT desktop_id, status, lease_expires_at, active_attempt_id
FROM desktop_tasks
WHERE kind = 'monitor'
AND monitor_task_id = $1
AND status IN ('queued', 'in_progress', 'unknown')
ORDER BY created_at DESC, id DESC
LIMIT 1
FOR UPDATE
`, spec.MonitorTaskID).Scan(&existingDesktopID, &existingStatus, &existingLeaseExpiresAt, &existingActiveAttempt)
err := tx.QueryRow(ctx, upsertMonitorDesktopTaskActiveLookupSQL(), spec.MonitorTaskID).Scan(&existingDesktopID, &existingStatus, &existingLeaseExpiresAt, &existingActiveAttempt)
switch err {
case nil:
task, getErr := repo.GetByDesktopID(ctx, existingDesktopID, spec.WorkspaceID)
@@ -771,6 +762,19 @@ func (s *MonitoringService) upsertMonitorDesktopTask(
return task, true, false, nil
}
func upsertMonitorDesktopTaskActiveLookupSQL() string {
return `
SELECT desktop_id, status, lease_expires_at, active_attempt_id
FROM desktop_tasks
WHERE kind = 'monitor'
AND monitor_task_id = $1
AND status IN ('queued', 'in_progress')
ORDER BY created_at DESC, id DESC
LIMIT 1
FOR UPDATE
`
}
func (s *MonitoringService) fallbackMonitorDesktopTasksToLegacy(ctx context.Context, taskIDs []int64) error {
if s == nil || s.monitoringPool == nil || len(taskIDs) == 0 {
return nil