next-issue 2.3.1 → 2.4.0
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 +5 -1
- package/dist/args.mjs +2 -1
- package/dist/cli.mjs +6 -1
- package/dist/serve.mjs +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -357,6 +357,7 @@ that a label still holds back stays as it was.
|
|
|
357
357
|
| --- | --- |
|
|
358
358
|
| `init` | Write the config file with the defaults |
|
|
359
359
|
| `serve` | Run the worker that pi extensions talk to, see [Worker](#worker) |
|
|
360
|
+
| `stop` | Stop the worker, see [Worker](#worker) |
|
|
360
361
|
| `--force` | Replace an existing config file, with `init` |
|
|
361
362
|
| `--once` | Stop after the first handled issue |
|
|
362
363
|
| `--max <n>` | Handle at most n issues |
|
|
@@ -423,7 +424,10 @@ to it. The worker:
|
|
|
423
424
|
- stops every agent and command and exits on `SIGTERM` or `SIGINT`, and
|
|
424
425
|
removes its socket and lock files.
|
|
425
426
|
|
|
426
|
-
Stop it
|
|
427
|
+
Stop it with `next-issue stop`. This sends `SIGTERM` to the process in the
|
|
428
|
+
lock file, so the worker stops at once and a run that is going resumes from
|
|
429
|
+
its saved state next time. When no worker is running, the command says so and
|
|
430
|
+
exits with 0.
|
|
427
431
|
|
|
428
432
|
## Development
|
|
429
433
|
|
package/dist/args.mjs
CHANGED
|
@@ -3,6 +3,7 @@ export const USAGE = `next-issue [command] [options]
|
|
|
3
3
|
|
|
4
4
|
init write ${CONFIG_FILE} with the defaults
|
|
5
5
|
serve run the worker that pi extensions talk to
|
|
6
|
+
stop stop the worker
|
|
6
7
|
|
|
7
8
|
--once stop after the first handled issue
|
|
8
9
|
--max <n> handle at most n issues
|
|
@@ -30,7 +31,7 @@ export function parseArgs(argv) {
|
|
|
30
31
|
for (let index = 0; index < argv.length; index += 1) {
|
|
31
32
|
const arg = argv[index];
|
|
32
33
|
if (index === 0 && !arg.startsWith("-")) {
|
|
33
|
-
if (arg !== "init" && arg !== "serve") {
|
|
34
|
+
if (arg !== "init" && arg !== "serve" && arg !== "stop") {
|
|
34
35
|
throw new Error(`Unknown command: ${arg}`);
|
|
35
36
|
}
|
|
36
37
|
args.command = arg;
|
package/dist/cli.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { ensureIgnored, repoRoot, WORKTREE_DIR } from "./git.mjs";
|
|
|
5
5
|
import { listenForInterrupts } from "./interrupt.mjs";
|
|
6
6
|
import { message } from "./observe.mjs";
|
|
7
7
|
import { runRepo } from "./run.mjs";
|
|
8
|
-
import { serve } from "./serve.mjs";
|
|
8
|
+
import { serve, socketPaths, stopWorker } from "./serve.mjs";
|
|
9
9
|
import { STATE_DIR } from "./state.mjs";
|
|
10
10
|
import { formatSummary } from "./summary.mjs";
|
|
11
11
|
function write(stream, text) {
|
|
@@ -22,6 +22,11 @@ async function main() {
|
|
|
22
22
|
if (args.command === "serve") {
|
|
23
23
|
return serve();
|
|
24
24
|
}
|
|
25
|
+
if (args.command === "stop") {
|
|
26
|
+
const pid = await stopWorker(socketPaths().lockPath);
|
|
27
|
+
await write(process.stdout, pid === undefined ? "next-issue: no worker is running\n" : `next-issue: stopped the worker with process id ${pid}\n`);
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
25
30
|
const root = await repoRoot(process.cwd());
|
|
26
31
|
if (args.command === "init") {
|
|
27
32
|
return init(root, args.force);
|
package/dist/serve.mjs
CHANGED
|
@@ -36,6 +36,17 @@ function alive(pid) {
|
|
|
36
36
|
return error.code === "EPERM";
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
async function holder(lockPath) {
|
|
40
|
+
const pid = Number((await readFile(lockPath, "utf8").catch(() => "")).trim());
|
|
41
|
+
return pid > 0 && alive(pid) ? pid : undefined;
|
|
42
|
+
}
|
|
43
|
+
export async function stopWorker(lockPath) {
|
|
44
|
+
const pid = await holder(lockPath);
|
|
45
|
+
if (pid !== undefined) {
|
|
46
|
+
process.kill(pid, "SIGTERM");
|
|
47
|
+
}
|
|
48
|
+
return pid;
|
|
49
|
+
}
|
|
39
50
|
async function lock(path) {
|
|
40
51
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
41
52
|
try {
|
|
@@ -46,8 +57,7 @@ async function lock(path) {
|
|
|
46
57
|
if (error.code !== "EEXIST") {
|
|
47
58
|
throw error;
|
|
48
59
|
}
|
|
49
|
-
|
|
50
|
-
if (pid > 0 && alive(pid)) {
|
|
60
|
+
if ((await holder(path)) !== undefined) {
|
|
51
61
|
return false;
|
|
52
62
|
}
|
|
53
63
|
await rm(path, { force: true });
|