fix: queue monitor tasks and recover doubao dom answers
Desktop Client Build / Resolve Build Metadata (push) Successful in 26s
Backend CI / Backend (push) Successful in 15m54s
Desktop Client Build / Build Desktop Client (push) Successful in 22m56s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 28s
Desktop Client Build / Resolve Build Metadata (push) Successful in 26s
Backend CI / Backend (push) Successful in 15m54s
Desktop Client Build / Build Desktop Client (push) Successful in 22m56s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 28s
This commit is contained in:
@@ -25,7 +25,10 @@ import (
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/repository"
|
||||
)
|
||||
|
||||
const desktopPublishMaxAttempts = 3
|
||||
const (
|
||||
desktopPublishMaxAttempts = 3
|
||||
maxConcurrentMonitorPlatformsPerDesktopClient = 2
|
||||
)
|
||||
|
||||
var errDesktopTaskLeaseDeferred = errors.New("desktop task lease deferred")
|
||||
|
||||
@@ -520,7 +523,13 @@ func (s *DesktopTaskService) leaseNextQueuedMonitorTask(
|
||||
}
|
||||
hasAccountIDs := len(accountIDs) > 0
|
||||
|
||||
row := s.pool.QueryRow(ctx, leaseNextQueuedMonitorTaskSQL(),
|
||||
tx, err := beginDesktopMonitorLeaseTx(ctx, s.pool, client.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
|
||||
row := tx.QueryRow(ctx, leaseNextQueuedMonitorTaskSQL(),
|
||||
client.TenantID,
|
||||
client.WorkspaceID,
|
||||
client.ID,
|
||||
@@ -528,8 +537,16 @@ func (s *DesktopTaskService) leaseNextQueuedMonitorTask(
|
||||
accountIDs,
|
||||
params.AttemptID,
|
||||
params.LeaseTokenHash,
|
||||
maxConcurrentMonitorPlatformsPerDesktopClient,
|
||||
)
|
||||
return scanRepositoryDesktopTask(row)
|
||||
task, err := scanRepositoryDesktopTask(row)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return nil, response.ErrInternal(50088, "desktop_task_lease_failed", "failed to commit desktop monitor task lease")
|
||||
}
|
||||
return task, nil
|
||||
}
|
||||
|
||||
func leaseNextQueuedMonitorTaskSQL() string {
|
||||
@@ -564,6 +581,16 @@ func leaseNextQueuedMonitorTaskSQL() string {
|
||||
AND recent.updated_at >= now() - interval '30 seconds'
|
||||
AND recent.desktop_id <> dt.desktop_id
|
||||
)
|
||||
AND (
|
||||
SELECT COUNT(DISTINCT active_platform.platform_id)
|
||||
FROM desktop_tasks AS active_platform
|
||||
WHERE active_platform.tenant_id = dt.tenant_id
|
||||
AND active_platform.workspace_id = dt.workspace_id
|
||||
AND active_platform.kind = 'monitor'
|
||||
AND active_platform.target_client_id = $3
|
||||
AND active_platform.status = 'in_progress'
|
||||
AND active_platform.desktop_id <> dt.desktop_id
|
||||
) < $8::integer
|
||||
AND (
|
||||
dt.target_client_id = $3
|
||||
OR ($4::boolean AND dt.target_account_id = ANY($5::uuid[]))
|
||||
@@ -658,7 +685,13 @@ func (s *DesktopTaskService) leaseQueuedDesktopTaskByID(
|
||||
}
|
||||
hasAccountIDs := len(accountIDs) > 0
|
||||
|
||||
row := s.pool.QueryRow(ctx, leaseQueuedDesktopTaskByIDSQL(),
|
||||
tx, err := beginDesktopMonitorLeaseTx(ctx, s.pool, client.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
|
||||
row := tx.QueryRow(ctx, leaseQueuedDesktopTaskByIDSQL(),
|
||||
desktopID,
|
||||
client.WorkspaceID,
|
||||
client.TenantID,
|
||||
@@ -668,8 +701,16 @@ func (s *DesktopTaskService) leaseQueuedDesktopTaskByID(
|
||||
params.AttemptID,
|
||||
params.LeaseTokenHash,
|
||||
desktopPublishMaxAttempts,
|
||||
maxConcurrentMonitorPlatformsPerDesktopClient,
|
||||
)
|
||||
return scanRepositoryDesktopTask(row)
|
||||
task, err := scanRepositoryDesktopTask(row)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return nil, response.ErrInternal(50088, "desktop_task_lease_failed", "failed to commit desktop task lease")
|
||||
}
|
||||
return task, nil
|
||||
}
|
||||
|
||||
func leaseQueuedDesktopTaskByIDSQL() string {
|
||||
@@ -722,6 +763,19 @@ func leaseQueuedDesktopTaskByIDSQL() string {
|
||||
AND recent.desktop_id <> dt.desktop_id
|
||||
)
|
||||
)
|
||||
AND (
|
||||
dt.kind <> 'monitor'
|
||||
OR (
|
||||
SELECT COUNT(DISTINCT active_platform.platform_id)
|
||||
FROM desktop_tasks AS active_platform
|
||||
WHERE active_platform.tenant_id = dt.tenant_id
|
||||
AND active_platform.workspace_id = dt.workspace_id
|
||||
AND active_platform.kind = 'monitor'
|
||||
AND active_platform.target_client_id = $4
|
||||
AND active_platform.status = 'in_progress'
|
||||
AND active_platform.desktop_id <> dt.desktop_id
|
||||
) < $10::integer
|
||||
)
|
||||
AND (
|
||||
(
|
||||
dt.kind = 'monitor'
|
||||
@@ -753,6 +807,21 @@ func leaseQueuedDesktopTaskByIDSQL() string {
|
||||
RETURNING ` + desktopTaskRepositoryReturningColumns
|
||||
}
|
||||
|
||||
func beginDesktopMonitorLeaseTx(ctx context.Context, pool *pgxpool.Pool, clientID uuid.UUID) (pgx.Tx, error) {
|
||||
if pool == nil {
|
||||
return nil, response.ErrInternal(50088, "desktop_task_lease_failed", "desktop task pool is not available")
|
||||
}
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50088, "desktop_task_lease_failed", "failed to start desktop monitor task lease")
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `SELECT pg_advisory_xact_lock($1)`, monitorDesktopTaskClientSlotLockKey(clientID)); err != nil {
|
||||
_ = tx.Rollback(ctx)
|
||||
return nil, response.ErrInternal(50088, "desktop_task_lease_failed", "failed to lock desktop monitor task lease")
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
func (s *DesktopTaskService) loadMonitorLeaseAccountIDs(ctx context.Context, client *repository.DesktopClient) ([]uuid.UUID, error) {
|
||||
if s == nil || client == nil || s.pool == nil {
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user