@@ -1490,49 +1490,6 @@ end
14901490
14911491local out = {}
14921492
1493- -- STALLED JOB RECOVERY WITH THROTTLING
1494- -- Check for stalled jobs periodically to avoid overhead in hot path
1495- -- This ensures stalled jobs are recovered even in high-load systems where ready queue is never empty
1496- -- Check interval is adaptive: 1/4 of jobTimeout (to check 4x during visibility window), max 5s
1497- local stalledCheckKey = ns .. ":stalled:lastcheck"
1498- local lastCheck = tonumber(redis.call("GET", stalledCheckKey)) or 0
1499- local stalledCheckInterval = math.min(math.floor(vt / 4), 5000)
1500-
1501- if (now - lastCheck) >= stalledCheckInterval then
1502- -- Update last check timestamp
1503- redis.call("SET", stalledCheckKey, tostring(now))
1504-
1505- -- Check for expired jobs and recover them
1506- local expiredJobs = redis.call("ZRANGEBYSCORE", processingKey, 0, now)
1507- if #expiredJobs > 0 then
1508- for _, jobId in ipairs(expiredJobs) do
1509- local deadlineAt = tonumber(redis.call("ZSCORE", processingKey, jobId))
1510- local gid = redis.call("HGET", ns .. ":job:" .. jobId, "groupId")
1511- if gid and deadlineAt and now > deadlineAt then
1512- local jobKey = ns .. ":job:" .. jobId
1513- local jobScore = redis.call("HGET", jobKey, "score")
1514- if jobScore then
1515- local gZ = ns .. ":g:" .. gid
1516- -- Remove from group active list BEFORE re-adding to group set
1517- -- This prevents the job from blocking the group after recovery
1518- local groupActiveKey = ns .. ":g:" .. gid .. ":active"
1519- redis.call("LREM", groupActiveKey, 1, jobId)
1520- redis.call("ZADD", gZ, tonumber(jobScore), jobId)
1521- -- Reset status so the job is visible as waiting again
1522- redis.call("HSET", jobKey, "status", "waiting")
1523- local head = redis.call("ZRANGE", gZ, 0, 0, "WITHSCORES")
1524- if head and #head >= 2 then
1525- local headScore = tonumber(head[2])
1526- redis.call("ZADD", readyKey, headScore, gid)
1527- end
1528- redis.call("DEL", ns .. ":lock:" .. gid)
1529- redis.call("ZREM", processingKey, jobId)
1530- end
1531- end
1532- end
1533- end
1534- end
1535-
15361493-- Pop up to maxBatch groups from ready set (lowest score first)
15371494local groups = redis.call("ZRANGE", readyKey, 0, maxBatch - 1, "WITHSCORES")
15381495if not groups or #groups == 0 then
0 commit comments