fix: throttle desktop monitoring dispatch
Desktop Client Build / Resolve Build Metadata (push) Successful in 27s
Backend CI / Backend (push) Successful in 15m57s
Desktop Client Build / Build Desktop Client (push) Successful in 22m57s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 27s
Desktop Client Build / Resolve Build Metadata (push) Successful in 27s
Backend CI / Backend (push) Successful in 15m57s
Desktop Client Build / Build Desktop Client (push) Successful in 22m57s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 27s
This commit is contained in:
@@ -514,7 +514,20 @@ func (s *DesktopTaskService) leaseNextQueuedMonitorTask(
|
||||
}
|
||||
hasAccountIDs := len(accountIDs) > 0
|
||||
|
||||
row := s.pool.QueryRow(ctx, `
|
||||
row := s.pool.QueryRow(ctx, leaseNextQueuedMonitorTaskSQL(),
|
||||
client.TenantID,
|
||||
client.WorkspaceID,
|
||||
client.ID,
|
||||
hasAccountIDs,
|
||||
accountIDs,
|
||||
params.AttemptID,
|
||||
params.LeaseTokenHash,
|
||||
)
|
||||
return scanRepositoryDesktopTask(row)
|
||||
}
|
||||
|
||||
func leaseNextQueuedMonitorTaskSQL() string {
|
||||
return `
|
||||
WITH candidate AS (
|
||||
SELECT dt.desktop_id
|
||||
FROM desktop_tasks AS dt
|
||||
@@ -522,6 +535,29 @@ func (s *DesktopTaskService) leaseNextQueuedMonitorTask(
|
||||
AND dt.workspace_id = $2
|
||||
AND dt.kind = 'monitor'
|
||||
AND dt.status = 'queued'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM desktop_tasks AS active
|
||||
WHERE active.tenant_id = dt.tenant_id
|
||||
AND active.workspace_id = dt.workspace_id
|
||||
AND active.kind = 'monitor'
|
||||
AND active.target_client_id = $3
|
||||
AND active.platform_id = dt.platform_id
|
||||
AND active.status = 'in_progress'
|
||||
AND active.desktop_id <> dt.desktop_id
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM desktop_tasks AS recent
|
||||
WHERE recent.tenant_id = dt.tenant_id
|
||||
AND recent.workspace_id = dt.workspace_id
|
||||
AND recent.kind = 'monitor'
|
||||
AND recent.target_client_id = $3
|
||||
AND recent.platform_id = dt.platform_id
|
||||
AND recent.status IN ('succeeded', 'failed', 'unknown', 'aborted')
|
||||
AND recent.updated_at >= now() - interval '30 seconds'
|
||||
AND recent.desktop_id <> dt.desktop_id
|
||||
)
|
||||
AND (
|
||||
dt.target_client_id = $3
|
||||
OR ($4::boolean AND dt.target_account_id = ANY($5::uuid[]))
|
||||
@@ -544,16 +580,7 @@ func (s *DesktopTaskService) leaseNextQueuedMonitorTask(
|
||||
updated_at = now()
|
||||
FROM candidate
|
||||
WHERE t.desktop_id = candidate.desktop_id
|
||||
RETURNING `+desktopTaskRepositoryReturningColumns,
|
||||
client.TenantID,
|
||||
client.WorkspaceID,
|
||||
client.ID,
|
||||
hasAccountIDs,
|
||||
accountIDs,
|
||||
params.AttemptID,
|
||||
params.LeaseTokenHash,
|
||||
)
|
||||
return scanRepositoryDesktopTask(row)
|
||||
RETURNING ` + desktopTaskRepositoryReturningColumns
|
||||
}
|
||||
|
||||
func (s *DesktopTaskService) leaseNextQueuedPublishTask(
|
||||
@@ -625,7 +652,22 @@ func (s *DesktopTaskService) leaseQueuedDesktopTaskByID(
|
||||
}
|
||||
hasAccountIDs := len(accountIDs) > 0
|
||||
|
||||
row := s.pool.QueryRow(ctx, `
|
||||
row := s.pool.QueryRow(ctx, leaseQueuedDesktopTaskByIDSQL(),
|
||||
desktopID,
|
||||
client.WorkspaceID,
|
||||
client.TenantID,
|
||||
client.ID,
|
||||
hasAccountIDs,
|
||||
accountIDs,
|
||||
params.AttemptID,
|
||||
params.LeaseTokenHash,
|
||||
desktopPublishMaxAttempts,
|
||||
)
|
||||
return scanRepositoryDesktopTask(row)
|
||||
}
|
||||
|
||||
func leaseQueuedDesktopTaskByIDSQL() string {
|
||||
return `
|
||||
WITH candidate AS (
|
||||
SELECT dt.desktop_id
|
||||
FROM desktop_tasks AS dt
|
||||
@@ -645,6 +687,35 @@ func (s *DesktopTaskService) leaseQueuedDesktopTaskByID(
|
||||
AND pa.delete_requested_at IS NULL
|
||||
)
|
||||
)
|
||||
AND (
|
||||
dt.kind <> 'monitor'
|
||||
OR NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM desktop_tasks AS active
|
||||
WHERE active.tenant_id = dt.tenant_id
|
||||
AND active.workspace_id = dt.workspace_id
|
||||
AND active.kind = 'monitor'
|
||||
AND active.target_client_id = $4
|
||||
AND active.platform_id = dt.platform_id
|
||||
AND active.status = 'in_progress'
|
||||
AND active.desktop_id <> dt.desktop_id
|
||||
)
|
||||
)
|
||||
AND (
|
||||
dt.kind <> 'monitor'
|
||||
OR NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM desktop_tasks AS recent
|
||||
WHERE recent.tenant_id = dt.tenant_id
|
||||
AND recent.workspace_id = dt.workspace_id
|
||||
AND recent.kind = 'monitor'
|
||||
AND recent.target_client_id = $4
|
||||
AND recent.platform_id = dt.platform_id
|
||||
AND recent.status IN ('succeeded', 'failed', 'unknown', 'aborted')
|
||||
AND recent.updated_at >= now() - interval '30 seconds'
|
||||
AND recent.desktop_id <> dt.desktop_id
|
||||
)
|
||||
)
|
||||
AND (
|
||||
(
|
||||
dt.kind = 'monitor'
|
||||
@@ -673,18 +744,7 @@ func (s *DesktopTaskService) leaseQueuedDesktopTaskByID(
|
||||
updated_at = now()
|
||||
FROM candidate
|
||||
WHERE t.desktop_id = candidate.desktop_id
|
||||
RETURNING `+desktopTaskRepositoryReturningColumns,
|
||||
desktopID,
|
||||
client.WorkspaceID,
|
||||
client.TenantID,
|
||||
client.ID,
|
||||
hasAccountIDs,
|
||||
accountIDs,
|
||||
params.AttemptID,
|
||||
params.LeaseTokenHash,
|
||||
desktopPublishMaxAttempts,
|
||||
)
|
||||
return scanRepositoryDesktopTask(row)
|
||||
RETURNING ` + desktopTaskRepositoryReturningColumns
|
||||
}
|
||||
|
||||
func (s *DesktopTaskService) loadMonitorLeaseAccountIDs(ctx context.Context, client *repository.DesktopClient) ([]uuid.UUID, error) {
|
||||
|
||||
Reference in New Issue
Block a user