fix monitor desktop unknown recovery
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user