feat(monitoring): dispatch monitoring tasks to desktop via AMQP outbox
Replace SSE /desktop/events with priority AMQP dispatch for monitoring
runs, and add phase1/phase2 infrastructure so desktop workers can lease,
resume, report, skip, and cancel monitoring tasks over the existing
dispatch WebSocket.
- Add monitoring collect outbox worker and phase2 desktop task fields
- Add /desktop/monitoring/tasks/{lease,resume,result,skip,cancel} routes
- Introduce execution-devtools and network-observer on desktop runtime
- Refactor runtime-controller, LoginView, and doubao adapter for the new flow
- Add channelName column to tracking views
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
const (
|
||||
monitoringLeaseMaxRetryCount = 1
|
||||
monitoringLeaseExpiredErrPrefix = "monitoring lease expired before result callback"
|
||||
monitoringStaleTaskDropReason = "stale_business_date"
|
||||
monitoringStaleTaskDropError = "monitoring task dropped after business day rollover"
|
||||
)
|
||||
|
||||
func expireMonitoringLeasedTasks(ctx context.Context, tx pgx.Tx, tenantID *int64, now time.Time) (int64, error) {
|
||||
@@ -78,6 +80,44 @@ func requeueMonitoringExpiredTasks(ctx context.Context, tx pgx.Tx, tenantID int6
|
||||
return tag.RowsAffected(), nil
|
||||
}
|
||||
|
||||
func skipMonitoringTasksBeforeBusinessDate(
|
||||
ctx context.Context,
|
||||
tx pgx.Tx,
|
||||
tenantID int64,
|
||||
businessDate time.Time,
|
||||
executionOwner string,
|
||||
) (int64, error) {
|
||||
if tx == nil {
|
||||
return 0, nil
|
||||
}
|
||||
if executionOwner == "" {
|
||||
executionOwner = "legacy"
|
||||
}
|
||||
|
||||
tag, err := tx.Exec(ctx, `
|
||||
UPDATE monitoring_collect_tasks
|
||||
SET status = 'skipped',
|
||||
lease_token_hash = NULL,
|
||||
leased_to_executor = NULL,
|
||||
leased_at = NULL,
|
||||
lease_expires_at = NULL,
|
||||
completed_at = COALESCE(completed_at, NOW()),
|
||||
skip_reason = $4,
|
||||
error_message = COALESCE(NULLIF(error_message, ''), $5),
|
||||
updated_at = NOW()
|
||||
WHERE tenant_id = $1
|
||||
AND collector_type = $2
|
||||
AND business_date < $3::date
|
||||
AND COALESCE(execution_owner, 'legacy') = $6
|
||||
AND callback_received_at IS NULL
|
||||
AND status IN ('pending', 'leased', 'expired')
|
||||
`, tenantID, monitoringCollectorType, businessDate.Format("2006-01-02"), monitoringStaleTaskDropReason, monitoringStaleTaskDropError, executionOwner)
|
||||
if err != nil {
|
||||
return 0, monitoringInternalError(50041, "task_skip_failed", "failed to drop stale monitoring tasks", err)
|
||||
}
|
||||
return tag.RowsAffected(), nil
|
||||
}
|
||||
|
||||
func ExpireMonitoringLeasedTasks(ctx context.Context, tx pgx.Tx, tenantID *int64, now time.Time) (int64, error) {
|
||||
return expireMonitoringLeasedTasks(ctx, tx, tenantID, now)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user