next-issue 6.3.2 → 6.3.4
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/README.md +3 -0
- package/dist/serve.mjs +18 -1
- package/dist/worker-run.mjs +3 -3
- package/dist/worker-server.mjs +24 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -547,6 +547,9 @@ affect another. The worker:
|
|
|
547
547
|
- holds `.next-issue/worker.lock` in the repository, with its process id, so
|
|
548
548
|
only one worker runs per repository. A lock whose process is no longer alive
|
|
549
549
|
is taken over;
|
|
550
|
+
- refuses a `start`, `stop` or `questions` message whose `root` is not
|
|
551
|
+
the exact path of its repository with an `error` message, and starts or
|
|
552
|
+
stops nothing;
|
|
550
553
|
- runs at most one run at a time. A client starts it with
|
|
551
554
|
`{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like
|
|
552
555
|
`next-issue` with those args, or with none when `args` is left out. It takes
|
package/dist/serve.mjs
CHANGED
|
@@ -81,6 +81,13 @@ export async function startWorker(options) {
|
|
|
81
81
|
closeWhenIdle();
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
+
else if (value.root !== options.root) {
|
|
85
|
+
send(socket, {
|
|
86
|
+
type: 'error',
|
|
87
|
+
root: value.root,
|
|
88
|
+
message: `the worker serves ${options.root} only`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
84
91
|
else if (value.type === 'start') {
|
|
85
92
|
start(socket, value.root, value.args ?? []);
|
|
86
93
|
}
|
|
@@ -98,9 +105,19 @@ export async function startWorker(options) {
|
|
|
98
105
|
socket.on('close', closeWhenIdle);
|
|
99
106
|
socket.on('message', (data) => {
|
|
100
107
|
const value = parseMessage(String(data));
|
|
101
|
-
if (value
|
|
108
|
+
if (value === undefined) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
102
112
|
receive(socket, value);
|
|
103
113
|
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
send(socket, {
|
|
116
|
+
type: 'error',
|
|
117
|
+
root: value.type === 'hello' ? options.root : value.root,
|
|
118
|
+
message: message(error),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
104
121
|
});
|
|
105
122
|
});
|
|
106
123
|
await listen(server, options.socketPath);
|
package/dist/worker-run.mjs
CHANGED
|
@@ -15,12 +15,12 @@ export function endStatus(run) {
|
|
|
15
15
|
return run.progress.error === undefined ? 'finished' : 'failed';
|
|
16
16
|
}
|
|
17
17
|
export function startRefusal(run, restart) {
|
|
18
|
-
if (active(run)) {
|
|
19
|
-
return 'a run is going in this repository already';
|
|
20
|
-
}
|
|
21
18
|
if (restart) {
|
|
22
19
|
return 'the worker is restarting, try again soon';
|
|
23
20
|
}
|
|
21
|
+
if (active(run)) {
|
|
22
|
+
return 'a run is going in this repository already';
|
|
23
|
+
}
|
|
24
24
|
return undefined;
|
|
25
25
|
}
|
|
26
26
|
export function runsMessage(runs) {
|
package/dist/worker-server.mjs
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import { send } from './questions.mjs';
|
|
3
3
|
import { runsMessage } from './worker-run.mjs';
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function isStringArray(value) {
|
|
8
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
9
|
+
}
|
|
10
|
+
function isClientMessage(value) {
|
|
11
|
+
if (!isRecord(value) || typeof value['type'] !== 'string') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (value['type'] === 'hello') {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (typeof value['root'] !== 'string') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (value['type'] === 'questions') {
|
|
21
|
+
return value['id'] === undefined || typeof value['id'] === 'string';
|
|
22
|
+
}
|
|
23
|
+
return value['type'] !== 'start' || value['args'] === undefined || isStringArray(value['args']);
|
|
24
|
+
}
|
|
4
25
|
export function parseMessage(text) {
|
|
26
|
+
let value;
|
|
5
27
|
try {
|
|
6
|
-
|
|
28
|
+
value = JSON.parse(text);
|
|
7
29
|
}
|
|
8
30
|
catch {
|
|
9
31
|
return undefined;
|
|
10
32
|
}
|
|
33
|
+
return isClientMessage(value) ? value : undefined;
|
|
11
34
|
}
|
|
12
35
|
export function broadcast(sockets, runs) {
|
|
13
36
|
const value = runsMessage(runs);
|