faces-cli 1.7.7 → 1.7.8
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/dist/commands/compile/doc/pause.d.ts +3 -0
- package/dist/commands/compile/doc/pause.js +52 -5
- package/dist/commands/compile/thread/pause.d.ts +3 -0
- package/dist/commands/compile/thread/pause.js +53 -5
- package/dist/poll.d.ts +21 -0
- package/dist/poll.js +34 -0
- package/oclif.manifest.json +454 -426
- package/package.json +1 -1
|
@@ -2,6 +2,8 @@ import { BaseCommand } from '../../../base.js';
|
|
|
2
2
|
export default class CompileDocPause extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
+
'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
6
|
+
timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
5
7
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
8
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
9
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -10,4 +12,5 @@ export default class CompileDocPause extends BaseCommand {
|
|
|
10
12
|
doc_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
11
13
|
};
|
|
12
14
|
run(): Promise<unknown>;
|
|
15
|
+
private report;
|
|
13
16
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import { Args } from '@oclif/core';
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import { BaseCommand } from '../../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../../client.js';
|
|
4
|
+
import { pollUntilPaused } from '../../../poll.js';
|
|
4
5
|
export default class CompileDocPause extends BaseCommand {
|
|
5
|
-
static description = '
|
|
6
|
+
static description = 'Ask a running document compilation to stop (preserves progress, resume with make). ' +
|
|
7
|
+
'The compile stops at the next chunk boundary; this waits for it unless --no-wait.';
|
|
6
8
|
static flags = {
|
|
7
9
|
...BaseCommand.baseFlags,
|
|
10
|
+
'no-wait': Flags.boolean({
|
|
11
|
+
description: 'Return as soon as the pause is accepted, without waiting for the compile to stop.',
|
|
12
|
+
default: false,
|
|
13
|
+
}),
|
|
14
|
+
timeout: Flags.integer({ description: 'Seconds to wait for the compile to stop (default: 60)', default: 60 }),
|
|
8
15
|
};
|
|
9
16
|
static args = {
|
|
10
17
|
doc_id: Args.string({ description: 'Document ID', required: true }),
|
|
@@ -12,6 +19,7 @@ export default class CompileDocPause extends BaseCommand {
|
|
|
12
19
|
async run() {
|
|
13
20
|
const { args, flags } = await this.parse(CompileDocPause);
|
|
14
21
|
const client = this.makeClient(flags);
|
|
22
|
+
const json = this.jsonEnabled();
|
|
15
23
|
let data;
|
|
16
24
|
try {
|
|
17
25
|
data = await client.post(`/v1/compile/documents/${args.doc_id}/pause`);
|
|
@@ -21,9 +29,48 @@ export default class CompileDocPause extends BaseCommand {
|
|
|
21
29
|
this.error(`Error (${err.statusCode}): ${err.message}`);
|
|
22
30
|
throw err;
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
// POST /pause only acknowledges the request — it answers "pausing", not
|
|
33
|
+
// "paused". Reporting it as stopped here would be a guess, and before the
|
|
34
|
+
// backend fix it was usually a wrong one. prepare_status is the authority.
|
|
35
|
+
if (flags['no-wait']) {
|
|
36
|
+
if (!json) {
|
|
37
|
+
process.stderr.write(`Pausing. Poll with: faces compile:doc:get ${args.doc_id} --json\n`);
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
if (!json)
|
|
42
|
+
process.stderr.write('Pausing');
|
|
43
|
+
const status = await pollUntilPaused(client, args.doc_id, {
|
|
44
|
+
timeoutMs: flags.timeout * 1000,
|
|
45
|
+
onTick: () => {
|
|
46
|
+
if (!json && process.stderr.isTTY)
|
|
47
|
+
process.stderr.write('.');
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (!json)
|
|
51
|
+
process.stderr.write('\n');
|
|
52
|
+
if (!json)
|
|
53
|
+
this.log(this.report(status, args.doc_id, flags.timeout));
|
|
54
|
+
return { ...data, prepare_status: status ?? null };
|
|
55
|
+
}
|
|
56
|
+
report(status, id, timeout) {
|
|
57
|
+
switch (status) {
|
|
58
|
+
case 'paused': {
|
|
59
|
+
return `Paused. Resume with: faces compile:doc:make ${id}`;
|
|
60
|
+
}
|
|
61
|
+
case 'synced':
|
|
62
|
+
case 'ready': {
|
|
63
|
+
return 'Compile finished before the pause took effect — nothing to resume.';
|
|
64
|
+
}
|
|
65
|
+
case 'failed': {
|
|
66
|
+
return 'Compile failed before the pause took effect.';
|
|
67
|
+
}
|
|
68
|
+
case null: {
|
|
69
|
+
return 'Stopped — the compile is no longer running.';
|
|
70
|
+
}
|
|
71
|
+
default: {
|
|
72
|
+
return `Still stopping after ${timeout}s. Poll with: faces compile:doc:get ${id} --json`;
|
|
73
|
+
}
|
|
26
74
|
}
|
|
27
|
-
return data;
|
|
28
75
|
}
|
|
29
76
|
}
|
|
@@ -2,6 +2,8 @@ import { BaseCommand } from '../../../base.js';
|
|
|
2
2
|
export default class CompileThreadPause extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
+
'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
6
|
+
timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
5
7
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
8
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
9
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -10,4 +12,5 @@ export default class CompileThreadPause extends BaseCommand {
|
|
|
10
12
|
thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
11
13
|
};
|
|
12
14
|
run(): Promise<unknown>;
|
|
15
|
+
private report;
|
|
13
16
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import { Args } from '@oclif/core';
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import { BaseCommand } from '../../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../../client.js';
|
|
4
|
+
import { pollUntilPaused } from '../../../poll.js';
|
|
4
5
|
export default class CompileThreadPause extends BaseCommand {
|
|
5
|
-
static description = '
|
|
6
|
+
static description = 'Ask a running thread compilation to stop (preserves progress, resume with make). ' +
|
|
7
|
+
'The compile stops at the next chunk boundary; this waits for it unless --no-wait.';
|
|
6
8
|
static flags = {
|
|
7
9
|
...BaseCommand.baseFlags,
|
|
10
|
+
'no-wait': Flags.boolean({
|
|
11
|
+
description: 'Return as soon as the pause is accepted, without waiting for the compile to stop.',
|
|
12
|
+
default: false,
|
|
13
|
+
}),
|
|
14
|
+
timeout: Flags.integer({ description: 'Seconds to wait for the compile to stop (default: 60)', default: 60 }),
|
|
8
15
|
};
|
|
9
16
|
static args = {
|
|
10
17
|
thread_id: Args.string({ description: 'Thread ID', required: true }),
|
|
@@ -12,6 +19,7 @@ export default class CompileThreadPause extends BaseCommand {
|
|
|
12
19
|
async run() {
|
|
13
20
|
const { args, flags } = await this.parse(CompileThreadPause);
|
|
14
21
|
const client = this.makeClient(flags);
|
|
22
|
+
const json = this.jsonEnabled();
|
|
15
23
|
let data;
|
|
16
24
|
try {
|
|
17
25
|
data = await client.post(`/v1/compile/threads/${args.thread_id}/pause`);
|
|
@@ -21,9 +29,49 @@ export default class CompileThreadPause extends BaseCommand {
|
|
|
21
29
|
this.error(`Error (${err.statusCode}): ${err.message}`);
|
|
22
30
|
throw err;
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
// POST /pause only acknowledges the request — it answers "pausing", not
|
|
33
|
+
// "paused". Reporting it as stopped here would be a guess, and before the
|
|
34
|
+
// backend fix it was usually a wrong one. prepare_status is the authority.
|
|
35
|
+
if (flags['no-wait']) {
|
|
36
|
+
if (!json) {
|
|
37
|
+
process.stderr.write(`Pausing. Poll with: faces compile:thread:get ${args.thread_id} --json\n`);
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
if (!json)
|
|
42
|
+
process.stderr.write('Pausing');
|
|
43
|
+
const status = await pollUntilPaused(client, args.thread_id, {
|
|
44
|
+
endpoint: `/v1/compile/threads/${args.thread_id}`,
|
|
45
|
+
timeoutMs: flags.timeout * 1000,
|
|
46
|
+
onTick: () => {
|
|
47
|
+
if (!json && process.stderr.isTTY)
|
|
48
|
+
process.stderr.write('.');
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
if (!json)
|
|
52
|
+
process.stderr.write('\n');
|
|
53
|
+
if (!json)
|
|
54
|
+
this.log(this.report(status, args.thread_id, flags.timeout));
|
|
55
|
+
return { ...data, prepare_status: status ?? null };
|
|
56
|
+
}
|
|
57
|
+
report(status, id, timeout) {
|
|
58
|
+
switch (status) {
|
|
59
|
+
case 'paused': {
|
|
60
|
+
return `Paused. Resume with: faces compile:thread:make ${id}`;
|
|
61
|
+
}
|
|
62
|
+
case 'synced':
|
|
63
|
+
case 'ready': {
|
|
64
|
+
return 'Compile finished before the pause took effect — nothing to resume.';
|
|
65
|
+
}
|
|
66
|
+
case 'failed': {
|
|
67
|
+
return 'Compile failed before the pause took effect.';
|
|
68
|
+
}
|
|
69
|
+
case null: {
|
|
70
|
+
return 'Stopped — the compile is no longer running.';
|
|
71
|
+
}
|
|
72
|
+
default: {
|
|
73
|
+
return `Still stopping after ${timeout}s. Poll with: faces compile:thread:get ${id} --json`;
|
|
74
|
+
}
|
|
26
75
|
}
|
|
27
|
-
return data;
|
|
28
76
|
}
|
|
29
77
|
}
|
package/dist/poll.d.ts
CHANGED
|
@@ -30,3 +30,24 @@ export interface PollOptions {
|
|
|
30
30
|
* Throws on timeout or failure.
|
|
31
31
|
*/
|
|
32
32
|
export declare function pollCompileProgress(client: FacesClient, id: string, opts?: PollOptions): Promise<unknown>;
|
|
33
|
+
export interface PausePollOptions {
|
|
34
|
+
intervalMs?: number;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
onTick?: () => void;
|
|
37
|
+
/** Override the GET endpoint path. Defaults to /v1/compile/documents/{id}. */
|
|
38
|
+
endpoint?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wait for a pause request to actually land.
|
|
42
|
+
*
|
|
43
|
+
* POST /pause only acknowledges the request — it returns `status: "pausing"` and
|
|
44
|
+
* the compile stops at the next chunk boundary, usually within a few seconds.
|
|
45
|
+
* `prepare_status` on the document is the authority on whether it has stopped.
|
|
46
|
+
*
|
|
47
|
+
* Returns that final status: `paused` when the pause landed, `synced`/`ready`
|
|
48
|
+
* when the compile finished before it could (a normal race, not an error),
|
|
49
|
+
* `failed` if it died, or null when nothing was running. Returns undefined if
|
|
50
|
+
* the timeout expires while it is still stopping — the pause was accepted
|
|
51
|
+
* either way, so callers should report rather than fail.
|
|
52
|
+
*/
|
|
53
|
+
export declare function pollUntilPaused(client: FacesClient, id: string, opts?: PausePollOptions): Promise<string | null | undefined>;
|
package/dist/poll.js
CHANGED
|
@@ -39,3 +39,37 @@ export async function pollCompileProgress(client, id, opts = {}) {
|
|
|
39
39
|
function sleep(ms) {
|
|
40
40
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Statuses that mean the compile is no longer running. `paused` is the outcome a
|
|
44
|
+
* pause is waiting for; the rest mean it stopped for some other reason first.
|
|
45
|
+
*/
|
|
46
|
+
const PAUSE_TERMINAL = new Set(['paused', 'synced', 'ready', 'failed']);
|
|
47
|
+
/**
|
|
48
|
+
* Wait for a pause request to actually land.
|
|
49
|
+
*
|
|
50
|
+
* POST /pause only acknowledges the request — it returns `status: "pausing"` and
|
|
51
|
+
* the compile stops at the next chunk boundary, usually within a few seconds.
|
|
52
|
+
* `prepare_status` on the document is the authority on whether it has stopped.
|
|
53
|
+
*
|
|
54
|
+
* Returns that final status: `paused` when the pause landed, `synced`/`ready`
|
|
55
|
+
* when the compile finished before it could (a normal race, not an error),
|
|
56
|
+
* `failed` if it died, or null when nothing was running. Returns undefined if
|
|
57
|
+
* the timeout expires while it is still stopping — the pause was accepted
|
|
58
|
+
* either way, so callers should report rather than fail.
|
|
59
|
+
*/
|
|
60
|
+
export async function pollUntilPaused(client, id, opts = {}) {
|
|
61
|
+
const interval = opts.intervalMs ?? 1000;
|
|
62
|
+
const timeout = opts.timeoutMs ?? 60_000;
|
|
63
|
+
const endpoint = opts.endpoint ?? `/v1/compile/documents/${id}`;
|
|
64
|
+
const start = Date.now();
|
|
65
|
+
while (Date.now() - start < timeout) {
|
|
66
|
+
await sleep(interval);
|
|
67
|
+
opts.onTick?.();
|
|
68
|
+
// status_only trims the body to the progress fields — this is a poll loop.
|
|
69
|
+
const data = await client.get(`${endpoint}?status_only=true`);
|
|
70
|
+
const status = data.prepare_status ?? null;
|
|
71
|
+
if (status === null || PAUSE_TERMINAL.has(status))
|
|
72
|
+
return status;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|