@nomac/cli 0.5.1 → 0.5.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/package.json +1 -1
- package/src/mac-transport.mjs +21 -2
package/package.json
CHANGED
package/src/mac-transport.mjs
CHANGED
|
@@ -25,8 +25,27 @@ export function transportOptions(options = {}) {
|
|
|
25
25
|
return { url, token, agent: proxy ? new HttpsProxyAgent(proxy) : undefined, ca: options.ca };
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
export
|
|
28
|
+
/** How long a busy guest is retried before guest_busy reaches the caller. */
|
|
29
|
+
export const GUEST_BUSY_RETRY = { budgetMs: 75_000, pauseMs: 3_000 };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A saturated guest (e.g. a first Simulator boot) answers slowly for a minute or
|
|
33
|
+
* two. Guest operations are idempotent by job ID, request key and blob offset, so
|
|
34
|
+
* only guest_busy is retried; every other failure is returned for reconciliation.
|
|
35
|
+
*/
|
|
36
|
+
export function macRequest(method, path, options = {}) {
|
|
37
|
+
const started = Date.now();
|
|
38
|
+
// The first attempt runs synchronously, so invalid input still throws immediately.
|
|
39
|
+
const attempt = () => macRequestOnce(method, path, options).catch(async error => {
|
|
40
|
+
if (error?.code !== "guest_busy" || Date.now() - started + GUEST_BUSY_RETRY.pauseMs + 15_000 > GUEST_BUSY_RETRY.budgetMs) throw error;
|
|
41
|
+
await new Promise(resolve => setTimeout(resolve, GUEST_BUSY_RETRY.pauseMs));
|
|
42
|
+
return attempt();
|
|
43
|
+
});
|
|
44
|
+
return attempt();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Bounded requests deliberately do not require streaming responses. */
|
|
48
|
+
function macRequestOnce(method, path, { body, raw, requestKey, ...options } = {}) {
|
|
30
49
|
const { url, token, agent, ca } = transportOptions(options);
|
|
31
50
|
if (!path.startsWith("/api/v1/mac/") || path.includes("#")) throw new CliError("Invalid Mac API path.");
|
|
32
51
|
const target = new URL(path, url);
|