feat(tenant): business-date-scope monitor lease lanes and authorization-failure cancellation
Add an optional lane filter to the monitor task lease so callers can pull a specific lane (e.g. high) and scope authorization-failure cancellation to the failing task's business date, so a challenge on one day no longer cancels queued tasks for another day. Monitor authorization-failure cancellation now requires a business date and no-ops without one. Also stop writing the nonexistent desktop_tasks.completed_at column when canceling queued tasks for an authorization failure. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -107,6 +107,7 @@ type LeaseDesktopTaskRequest struct {
|
||||
TaskID *string `json:"task_id"`
|
||||
Kind *string `json:"kind" binding:"omitempty,oneof=publish monitor"`
|
||||
PlatformIDs []string `json:"platform_ids"`
|
||||
Lanes []string `json:"lanes"`
|
||||
}
|
||||
|
||||
type LeaseDesktopTaskResponse struct {
|
||||
@@ -216,6 +217,7 @@ func (s *DesktopTaskService) Lease(ctx context.Context, client *repository.Deskt
|
||||
LeaseTokenHash: tokenHash,
|
||||
}
|
||||
eligiblePlatformIDs := normalizeDesktopTaskLeasePlatformIDs(req.PlatformIDs)
|
||||
eligibleLanes := normalizeDesktopTaskLeaseLanes(req.Lanes)
|
||||
|
||||
if s.logger != nil {
|
||||
fields := []zap.Field{
|
||||
@@ -235,7 +237,7 @@ func (s *DesktopTaskService) Lease(ctx context.Context, client *repository.Deskt
|
||||
case taskID != nil:
|
||||
task, err = s.leaseQueuedDesktopTaskByID(ctx, client, *taskID, leaseParams)
|
||||
case req.Kind != nil && strings.TrimSpace(*req.Kind) == "monitor":
|
||||
task, err = s.leaseNextQueuedMonitorTask(ctx, client, leaseParams, eligiblePlatformIDs)
|
||||
task, err = s.leaseNextQueuedMonitorTask(ctx, client, leaseParams, eligiblePlatformIDs, eligibleLanes)
|
||||
case req.Kind != nil && strings.TrimSpace(*req.Kind) == "publish":
|
||||
task, err = s.leaseNextQueuedPublishTask(ctx, client, leaseParams)
|
||||
default:
|
||||
@@ -523,6 +525,7 @@ func (s *DesktopTaskService) leaseNextQueuedMonitorTask(
|
||||
client *repository.DesktopClient,
|
||||
params repository.DesktopTaskLeaseParams,
|
||||
eligiblePlatformIDs []string,
|
||||
eligibleLanes []string,
|
||||
) (*repository.DesktopTask, error) {
|
||||
tx, err := beginDesktopMonitorLeaseTx(ctx, s.pool, client.ID)
|
||||
if err != nil {
|
||||
@@ -538,6 +541,7 @@ func (s *DesktopTaskService) leaseNextQueuedMonitorTask(
|
||||
params.LeaseTokenHash,
|
||||
maxConcurrentMonitorPlatformsPerDesktopClient,
|
||||
eligiblePlatformIDs,
|
||||
eligibleLanes,
|
||||
)
|
||||
task, err := scanRepositoryDesktopTask(row)
|
||||
if err != nil {
|
||||
@@ -582,10 +586,14 @@ func leaseNextQueuedMonitorTaskSQL() string {
|
||||
AND dt.platform_id = ca.platform_id
|
||||
AND dt.kind = 'monitor'
|
||||
AND dt.status = 'queued'
|
||||
AND (
|
||||
COALESCE(array_length($7::text[], 1), 0) = 0
|
||||
OR dt.platform_id = ANY($7::text[])
|
||||
)
|
||||
AND (
|
||||
COALESCE(array_length($7::text[], 1), 0) = 0
|
||||
OR dt.platform_id = ANY($7::text[])
|
||||
)
|
||||
AND (
|
||||
COALESCE(array_length($8::text[], 1), 0) = 0
|
||||
OR dt.lane = ANY($8::text[])
|
||||
)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM desktop_tasks AS active
|
||||
@@ -701,6 +709,32 @@ func normalizeDesktopTaskLeasePlatformIDs(values []string) []string {
|
||||
return result
|
||||
}
|
||||
|
||||
func normalizeDesktopTaskLeaseLanes(values []string) []string {
|
||||
allowed := map[string]struct{}{
|
||||
"high": {},
|
||||
"normal": {},
|
||||
"normal_boosted": {},
|
||||
"retry": {},
|
||||
}
|
||||
result := make([]string, 0, len(values))
|
||||
seen := make(map[string]struct{}, len(values))
|
||||
for _, value := range values {
|
||||
normalized := strings.ToLower(strings.TrimSpace(value))
|
||||
if _, ok := allowed[normalized]; !ok {
|
||||
continue
|
||||
}
|
||||
if _, exists := seen[normalized]; exists {
|
||||
continue
|
||||
}
|
||||
seen[normalized] = struct{}{}
|
||||
result = append(result, normalized)
|
||||
}
|
||||
if len(result) == 0 {
|
||||
return nil
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func monitorAccountLeaseLockSQL(alias string) string {
|
||||
return fmt.Sprintf(`hashtextextended(
|
||||
concat_ws(
|
||||
|
||||
Reference in New Issue
Block a user