@kevlns/art-workshop 0.4.0 → 0.4.1
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/lib/tasks.mjs +16 -7
- package/lib/worker-process.mjs +3 -1
- package/package.json +1 -1
package/lib/tasks.mjs
CHANGED
|
@@ -348,13 +348,22 @@ export async function shutdown(settings, { closeServices = true } = {}) {
|
|
|
348
348
|
)
|
|
349
349
|
await sleep(50);
|
|
350
350
|
// Never close the service while a live art worker is still using it.
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
(t)
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
351
|
+
const blockers = tasks(root).filter(
|
|
352
|
+
(t) =>
|
|
353
|
+
!executionSettled(taskStatus(root, t.taskId)) || workerAlive(t),
|
|
354
|
+
);
|
|
355
|
+
if (blockers.length)
|
|
356
|
+
throw new Error(
|
|
357
|
+
"任务尚未停止,保留服务:" +
|
|
358
|
+
(failures.length
|
|
359
|
+
? failures.join("; ")
|
|
360
|
+
: blockers
|
|
361
|
+
.map(
|
|
362
|
+
(t) =>
|
|
363
|
+
t.taskId + "(status=" + t.status + ", pid=" + t.workerPid + ")",
|
|
364
|
+
)
|
|
365
|
+
.join("; ")),
|
|
366
|
+
);
|
|
358
367
|
if (failures.length)
|
|
359
368
|
throw new Error("任务停止尚未确认,保留服务:" + failures.join("; "));
|
|
360
369
|
if (!closeServices)
|
package/lib/worker-process.mjs
CHANGED
|
@@ -6,7 +6,9 @@ import {hash} from './shared.mjs';
|
|
|
6
6
|
export function workerAlive(task, inspect = processIdentity) {
|
|
7
7
|
const pid = task.workerPid;
|
|
8
8
|
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
9
|
-
|
|
9
|
+
// ESRCH:PID 已消失。其余错误(Windows 的 EPERM/EACCES)只说明该 PID 存在
|
|
10
|
+
// 但不归我们管,通常是 PID 被复用;交给下面的身份比对判定。
|
|
11
|
+
try { process.kill(pid, 0); } catch (error) { if (error.code === 'ESRCH') return false; }
|
|
10
12
|
const current = inspect(pid);
|
|
11
13
|
if (!current) return true;
|
|
12
14
|
if (task.workerIdentity) return hash(current) === hash(task.workerIdentity);
|