[v1.4] 新增批次检查脚本的 timeout, 避免一个脚本更新时间太长导致所有脚本检查失败#1265
Merged
CodFrm merged 3 commits intoscriptscat:release/v1.4from Mar 16, 2026
Merged
[v1.4] 新增批次检查脚本的 timeout, 避免一个脚本更新时间太长导致所有脚本检查失败#1265CodFrm merged 3 commits intoscriptscat:release/v1.4from
CodFrm merged 3 commits intoscriptscat:release/v1.4from
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
本次 PR 主要针对 Service Worker 侧的脚本批量更新检查流程,加入整体超时控制并调整结果收集方式,以避免更新检查长时间阻塞并保证返回结果顺序稳定。
Changes:
- 为
checkUpdatesAvailable增加 5 分钟超时(Promise.race+sleep)。 - 使用
Map按 UUID 记录检查结果并在返回时保持顺序一致(未完成/失败默认false)。 - 将并行等待改为
Promise.allSettled,避免单个任务异常影响整体流程。
Comment on lines
+786
to
+801
| await Promise.race([ | ||
| sleep(300_000), // 5 minutes | ||
| Promise.allSettled( | ||
| (uuids as string[]).map(async (uuid, _idx) => { | ||
| results.set(uuid, false); // 確保次序 | ||
| const script = scripts[_idx]; | ||
| const res = | ||
| !script || script.uuid !== uuid || !checkScripts.includes(script) | ||
| ? false | ||
| : await this._checkUpdateAvailable(script, delayFn); | ||
| if (!res) return false; | ||
| results.set(uuid, res); | ||
| return res; | ||
| }) | ||
| ), | ||
| ]); |
Comment on lines
+786
to
+802
| await Promise.race([ | ||
| sleep(300_000), // 5 minutes | ||
| Promise.allSettled( | ||
| (uuids as string[]).map(async (uuid, _idx) => { | ||
| results.set(uuid, false); // 確保次序 | ||
| const script = scripts[_idx]; | ||
| const res = | ||
| !script || script.uuid !== uuid || !checkScripts.includes(script) | ||
| ? false | ||
| : await this._checkUpdateAvailable(script, delayFn); | ||
| if (!res) return false; | ||
| results.set(uuid, res); | ||
| return res; | ||
| }) | ||
| ), | ||
| ]); | ||
| return [...results.values()]; |
| sleep(300_000), // 5 minutes | ||
| Promise.allSettled( | ||
| (uuids as string[]).map(async (uuid, _idx) => { | ||
| results.set(uuid, false); // 確保次序 |
- fetchScriptBody 添加 AbortSignal 支持 - 繁体转简体:確保次序 → 确保顺序 - 用 setTimeout+clearTimeout 替代 sleep,超时后正确清理 - 超时时通过 AbortController 中止进行中的请求 - Map 预初始化确保返回顺序一致
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
更新时间超过 5分钟会被视为更新检查失败,直接跳过显示
这种脚本必须在手动更新那边
不加的话,一个导致其他脚本的更新都不显示了