dsh-aupdate 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +41 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1549,7 +1549,11 @@ function settingsSnapshot(config, ctxRef) {
|
|
|
1549
1549
|
history: readHistory().slice(0, 40),
|
|
1550
1550
|
historyPath: historyPath(),
|
|
1551
1551
|
// 下一轮什么时候跑:设置页把它直接显示出来,用户不用自己推算。
|
|
1552
|
-
|
|
1552
|
+
// 调度器已经把「这一轮真实等多久」记在 pendingMinutes 上,优先用它;
|
|
1553
|
+
// 取不到(比如定时器还没排上)才退回按当前规则现算。
|
|
1554
|
+
nextInMinutes: typeof ctxRef?.pendingMinutes === 'number'
|
|
1555
|
+
? ctxRef.pendingMinutes
|
|
1556
|
+
: nextDelayMinutes(settings, new Date()),
|
|
1553
1557
|
// 被抑制的 pkg@版本:让人看得见「为什么这个包不更新了」。
|
|
1554
1558
|
failures: readFailures().slice(0, 20).map((row) => {
|
|
1555
1559
|
const at = Date.parse(String(row.at ?? ''))
|
|
@@ -1586,12 +1590,9 @@ function settingsSnapshot(config, ctxRef) {
|
|
|
1586
1590
|
}
|
|
1587
1591
|
}
|
|
1588
1592
|
|
|
1589
|
-
function registerRoutes(
|
|
1590
|
-
const webServer = serviceOf(
|
|
1591
|
-
if (webServer === null || typeof webServer.register !== 'function')
|
|
1592
|
-
writeLog('webServer unavailable: settings page will report it')
|
|
1593
|
-
return false
|
|
1594
|
-
}
|
|
1593
|
+
function registerRoutes(scope, ctxRef) {
|
|
1594
|
+
const webServer = serviceOf(scope, 'webServer')
|
|
1595
|
+
if (webServer === null || typeof webServer.register !== 'function') return false
|
|
1595
1596
|
const handler = async (req, res) => {
|
|
1596
1597
|
try {
|
|
1597
1598
|
const url = new URL(req.url ?? '/', 'http://localhost')
|
|
@@ -1660,10 +1661,10 @@ function registerRoutes(ctx, ctxRef) {
|
|
|
1660
1661
|
}
|
|
1661
1662
|
}
|
|
1662
1663
|
try {
|
|
1663
|
-
const effect = propOf(
|
|
1664
|
+
const effect = propOf(scope, 'effect')
|
|
1664
1665
|
const register = () => webServer.register({ kind: 'prefix', path: ROUTE_PREFIX, handler })
|
|
1665
1666
|
if (typeof effect === 'function') {
|
|
1666
|
-
effect.call(
|
|
1667
|
+
effect.call(scope, register, 'dsh-aupdate: settings routes')
|
|
1667
1668
|
writeLog('settings route ready: ' + ROUTE_PREFIX)
|
|
1668
1669
|
return true
|
|
1669
1670
|
}
|
|
@@ -1701,19 +1702,44 @@ export function apply(ctx, config) {
|
|
|
1701
1702
|
writeLog('tool registration threw: ' + oneLine(error?.message ?? error, 300))
|
|
1702
1703
|
}
|
|
1703
1704
|
}
|
|
1705
|
+
// 路由和工具是同一类问题:apply 执行时 webServer 可能还没就绪,
|
|
1706
|
+
// 一次性取服务会静默失败且永不重试。同样放进动态 inject 作用域里重放。
|
|
1707
|
+
let routeService = null
|
|
1708
|
+
const offerRoutes = (scope) => {
|
|
1709
|
+
try {
|
|
1710
|
+
const webServer = serviceOf(scope, 'webServer')
|
|
1711
|
+
if (webServer === null || typeof webServer.register !== 'function') {
|
|
1712
|
+
writeLog('webServer unavailable: settings page will report it')
|
|
1713
|
+
return
|
|
1714
|
+
}
|
|
1715
|
+
if (routeService === webServer) return
|
|
1716
|
+
const ok = registerRoutes(scope, ctxRef)
|
|
1717
|
+
if (ok) routeService = webServer
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
writeLog('route registration threw: ' + oneLine(error?.message ?? error, 300))
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1704
1722
|
const inject = propOf(ctx, 'inject')
|
|
1705
1723
|
if (typeof inject === 'function') {
|
|
1724
|
+
// 兜底:inject 的作用域回调只在依赖齐备时重放,若是宿主不认 webServer
|
|
1725
|
+
// 这个依赖名,回调可能永远不来。所以先就地抢一次,拿不到再等重放。
|
|
1726
|
+
offerRoutes(ctx)
|
|
1706
1727
|
try {
|
|
1707
|
-
const fiber = inject.call(ctx, ['tools'],
|
|
1728
|
+
const fiber = inject.call(ctx, ['tools', 'webServer'], (scope) => {
|
|
1729
|
+
offerTool(scope)
|
|
1730
|
+
offerRoutes(scope)
|
|
1731
|
+
})
|
|
1708
1732
|
Promise.resolve(fiber).catch((error) => {
|
|
1709
1733
|
writeLog('tool scope ended: ' + oneLine(error?.message ?? error, 300))
|
|
1710
1734
|
})
|
|
1711
1735
|
} catch (error) {
|
|
1712
1736
|
writeLog('cannot offer the tool: ' + oneLine(error?.message ?? error, 300))
|
|
1713
1737
|
offerTool(ctx)
|
|
1738
|
+
offerRoutes(ctx)
|
|
1714
1739
|
}
|
|
1715
1740
|
} else {
|
|
1716
1741
|
offerTool(ctx)
|
|
1742
|
+
offerRoutes(ctx)
|
|
1717
1743
|
}
|
|
1718
1744
|
|
|
1719
1745
|
const runSafely = (mode) => {
|
|
@@ -1744,6 +1770,7 @@ export function apply(ctx, config) {
|
|
|
1744
1770
|
let firstPending = true
|
|
1745
1771
|
|
|
1746
1772
|
const clearScheduled = () => {
|
|
1773
|
+
ctxRef.pendingMinutes = null
|
|
1747
1774
|
if (scheduled === null) return
|
|
1748
1775
|
try {
|
|
1749
1776
|
clearTimeout(scheduled)
|
|
@@ -1762,6 +1789,10 @@ export function apply(ctx, config) {
|
|
|
1762
1789
|
// 启动后第一次仍然只看 firstDelayMinutes,之后按当前调度模式算。
|
|
1763
1790
|
const minutes = firstPending && live.checkOnStart ? live.firstDelayMinutes : nextDelayMinutes(live, new Date())
|
|
1764
1791
|
firstPending = false
|
|
1792
|
+
// 记下这一轮真实的等待时长,设置页按它显示「下一轮」。
|
|
1793
|
+
// 直接拿 nextDelayMinutes 算会漏掉启动后那次短期检查:明明 5 分钟后就要跑,
|
|
1794
|
+
// 面板却显示 1440 分钟,看的人只会以为「启动后根本不查」,于是手动点一次。
|
|
1795
|
+
ctxRef.pendingMinutes = minutes
|
|
1765
1796
|
const handle = setTimeout(() => {
|
|
1766
1797
|
scheduled = null
|
|
1767
1798
|
runSafely('update')
|
|
@@ -1786,7 +1817,6 @@ export function apply(ctx, config) {
|
|
|
1786
1817
|
|
|
1787
1818
|
// 设置页要能读到运行状态并改设置,所以路由最后注册、且与 enabled 无关:
|
|
1788
1819
|
// 关掉定时检查之后,用户仍然要能看到这一页并把它重新打开。
|
|
1789
|
-
registerRoutes(ctx, ctxRef)
|
|
1790
1820
|
if (!settings.enabled) writeLog('disabled by config; scheduler parked, settings page still live')
|
|
1791
1821
|
|
|
1792
1822
|
const stop = () => {
|