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

This commit is contained in:
2026-06-22 12:21:59 +08:00
parent 54c2f92e02
commit 8c6789dca6
23 changed files with 591 additions and 88 deletions
@@ -1371,15 +1371,18 @@ func (s *MonitoringCallbackService) loadCollectTask(ctx context.Context, tenantI
skip_reason,
trigger_source,
COALESCE(target_client_id::text, '') AS target_client_id,
COALESCE((
COALESCE(NULLIF(t.question_text_snapshot, ''), (
SELECT question_text_snapshot
FROM monitoring_question_config_snapshots
WHERE tenant_id = t.tenant_id
AND brand_id = t.brand_id
AND question_id = t.question_id
AND question_hash = t.question_hash
AND deleted_at IS NULL
ORDER BY projected_at DESC, id DESC
AND btrim(question_text_snapshot) <> ''
ORDER BY
CASE WHEN deleted_at IS NULL THEN 0 ELSE 1 END,
projected_at DESC,
id DESC
LIMIT 1
), '') AS question_text_snapshot
FROM monitoring_collect_tasks t
@@ -1439,15 +1442,18 @@ func (s *MonitoringCallbackService) loadCollectTaskByID(ctx context.Context, tas
skip_reason,
trigger_source,
COALESCE(target_client_id::text, '') AS target_client_id,
COALESCE((
COALESCE(NULLIF(t.question_text_snapshot, ''), (
SELECT question_text_snapshot
FROM monitoring_question_config_snapshots
WHERE tenant_id = t.tenant_id
AND brand_id = t.brand_id
AND question_id = t.question_id
AND question_hash = t.question_hash
AND deleted_at IS NULL
ORDER BY projected_at DESC, id DESC
AND btrim(question_text_snapshot) <> ''
ORDER BY
CASE WHEN deleted_at IS NULL THEN 0 ELSE 1 END,
projected_at DESC,
id DESC
LIMIT 1
), '') AS question_text_snapshot
FROM monitoring_collect_tasks t
@@ -1538,15 +1544,18 @@ func (s *MonitoringCallbackService) selectPendingLeaseTasks(
t.business_date,
COALESCE(t.dispatch_priority, 100) AS dispatch_priority,
COALESCE(t.dispatch_lane, 'normal') AS dispatch_lane,
COALESCE((
COALESCE(NULLIF(t.question_text_snapshot, ''), (
SELECT question_text_snapshot
FROM monitoring_question_config_snapshots
WHERE tenant_id = t.tenant_id
AND brand_id = t.brand_id
AND question_id = t.question_id
AND question_hash = t.question_hash
AND deleted_at IS NULL
ORDER BY projected_at DESC, id DESC
AND btrim(question_text_snapshot) <> ''
ORDER BY
CASE WHEN deleted_at IS NULL THEN 0 ELSE 1 END,
projected_at DESC,
id DESC
LIMIT 1
), '') AS question_text_snapshot
FROM monitoring_collect_tasks t
@@ -1650,15 +1659,18 @@ func (s *MonitoringCallbackService) selectLeasedTasksForInstallation(
t.business_date,
COALESCE(t.dispatch_priority, 100) AS dispatch_priority,
COALESCE(t.dispatch_lane, 'normal') AS dispatch_lane,
COALESCE((
COALESCE(NULLIF(t.question_text_snapshot, ''), (
SELECT question_text_snapshot
FROM monitoring_question_config_snapshots
WHERE tenant_id = t.tenant_id
AND brand_id = t.brand_id
AND question_id = t.question_id
AND question_hash = t.question_hash
AND deleted_at IS NULL
ORDER BY projected_at DESC, id DESC
AND btrim(question_text_snapshot) <> ''
ORDER BY
CASE WHEN deleted_at IS NULL THEN 0 ELSE 1 END,
projected_at DESC,
id DESC
LIMIT 1
), '') AS question_text_snapshot
FROM monitoring_collect_tasks t
@@ -2070,6 +2082,10 @@ func (s *MonitoringCallbackService) upsertParseResult(ctx context.Context, tx pg
}
func (s *MonitoringCallbackService) processTaskResult(ctx context.Context, task *monitoringCollectTask, req MonitoringTaskResultRequest) (*MonitoringTaskResultResponse, error) {
if task == nil || strings.TrimSpace(task.QuestionText) == "" {
return nil, response.ErrInternal(50041, "missing_question_text_snapshot", "monitoring task question text is empty")
}
req = normalizeMonitoringTaskResultRequestValue(req)
runStatus := normalizeRunStatus(req.Status)