@leiyi-works/dsh-auto-restart 0.1.1 → 0.1.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 +39 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -77,6 +77,10 @@ const DEFAULTS = Object.freeze({
|
|
|
77
77
|
maxIdleWaitMs: 120000,
|
|
78
78
|
/** 等空闲超时后是否仍然强重启;默认 false(放弃本次,等下次变化)。 */
|
|
79
79
|
forceWhenBusy: false,
|
|
80
|
+
/** 这些标记文件存在时(相对 DSH_HOME),说明有后台任务在跑,先等它结束再重启。 */
|
|
81
|
+
busyMarkers: ['.cloud-sync/sync-busy'],
|
|
82
|
+
/** 等后台任务结束的最长时间(毫秒),超时按 forceWhenBusy 处理。 */
|
|
83
|
+
busyWaitMs: 600000,
|
|
80
84
|
/** 守护进程收到请求后等多久动手(毫秒),留时间给当前回合收尾。 */
|
|
81
85
|
restartDelayMs: 2000,
|
|
82
86
|
/** 重启后把主窗口最大化(开关在左侧「自动重启」面板里)。 */
|
|
@@ -109,6 +113,16 @@ function dshHome() {
|
|
|
109
113
|
return typeof env === 'string' && env.trim() !== '' ? env.trim() : join(homedir(), '.dsh')
|
|
110
114
|
}
|
|
111
115
|
|
|
116
|
+
function activeBusyMarkers(cfg) {
|
|
117
|
+
const found = []
|
|
118
|
+
for (const rel of cfg.busyMarkers) {
|
|
119
|
+
try {
|
|
120
|
+
if (existsSync(join(dshHome(), rel))) found.push(rel)
|
|
121
|
+
} catch { /* 忽略 */ }
|
|
122
|
+
}
|
|
123
|
+
return found
|
|
124
|
+
}
|
|
125
|
+
|
|
112
126
|
function dataDir() {
|
|
113
127
|
return join(dshHome(), 'dsh-auto-restart')
|
|
114
128
|
}
|
|
@@ -220,6 +234,13 @@ function sanitizeConfig(raw) {
|
|
|
220
234
|
cfg.dryRun = bool(raw.dryRun, cfg.dryRun)
|
|
221
235
|
cfg.waitForIdle = bool(raw.waitForIdle, cfg.waitForIdle)
|
|
222
236
|
cfg.forceWhenBusy = bool(raw.forceWhenBusy, cfg.forceWhenBusy)
|
|
237
|
+
cfg.busyWaitMs = num(raw.busyWaitMs, cfg.busyWaitMs, 0, 3600000)
|
|
238
|
+
if (Array.isArray(raw.busyMarkers)) {
|
|
239
|
+
cfg.busyMarkers = raw.busyMarkers
|
|
240
|
+
.filter((item) => typeof item === 'string' && item.trim() !== '')
|
|
241
|
+
.slice(0, 8)
|
|
242
|
+
.map((item) => item.trim())
|
|
243
|
+
}
|
|
223
244
|
cfg.maximizeOnRestart = bool(raw.maximizeOnRestart, cfg.maximizeOnRestart)
|
|
224
245
|
cfg.pollIntervalMs = num(raw.pollIntervalMs, cfg.pollIntervalMs, 500, 60000)
|
|
225
246
|
cfg.stableMs = num(raw.stableMs, cfg.stableMs, 0, 600000)
|
|
@@ -528,6 +549,7 @@ function createState(profileDir) {
|
|
|
528
549
|
lastChangeAt: 0,
|
|
529
550
|
pendingSince: 0,
|
|
530
551
|
waitingSince: 0,
|
|
552
|
+
markerWaitingSince: 0,
|
|
531
553
|
lastRestartAt: persisted.lastRestartAt,
|
|
532
554
|
restarts: persisted.restarts.filter((t) => now - t < 3600000),
|
|
533
555
|
lastManagerAt: 0,
|
|
@@ -604,6 +626,23 @@ function tick(baseConfig) {
|
|
|
604
626
|
return
|
|
605
627
|
}
|
|
606
628
|
|
|
629
|
+
const markers = activeBusyMarkers(cfg)
|
|
630
|
+
if (markers.length > 0) {
|
|
631
|
+
if (state.markerWaitingSince === 0) {
|
|
632
|
+
state.markerWaitingSince = now
|
|
633
|
+
logLine('info', `检测到进行中的云同步(${markers.join('、')}),等它结束后再重启`)
|
|
634
|
+
return
|
|
635
|
+
}
|
|
636
|
+
if (now - state.markerWaitingSince <= cfg.busyWaitMs) return
|
|
637
|
+
if (!cfg.forceWhenBusy) {
|
|
638
|
+
abortPending(state, `云同步进行了 ${Math.round(cfg.busyWaitMs / 1000)}s 仍未结束,本次跳过重启`)
|
|
639
|
+
return
|
|
640
|
+
}
|
|
641
|
+
logLine('warn', `云同步超过 ${Math.round(cfg.busyWaitMs / 1000)}s,forceWhenBusy=true,按配置强重启`)
|
|
642
|
+
} else if (state.markerWaitingSince !== 0) {
|
|
643
|
+
state.markerWaitingSince = 0
|
|
644
|
+
}
|
|
645
|
+
|
|
607
646
|
if (cfg.waitForIdle && state.busy.size > 0) {
|
|
608
647
|
if (state.waitingSince === 0) {
|
|
609
648
|
state.waitingSince = now
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leiyi-works/dsh-auto-restart",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"title": "自动重启",
|
|
6
|
-
"description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile
|
|
6
|
+
"description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,等所有会话空闲,由脱离进程树的守护者先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和左侧「自动重启」面板。(0.1.2:云同步进行中(.cloud-sync/sync-busy 标记)自动等待其结束再重启)",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./index.js",
|