@limrun/api 0.74.0 → 0.76.0-rc.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/CHANGELOG.md +7 -0
- package/client.d.mts +4 -0
- package/client.d.mts.map +1 -1
- package/client.d.ts +4 -0
- package/client.d.ts.map +1 -1
- package/client.js +4 -0
- package/client.js.map +1 -1
- package/client.mjs +4 -0
- package/client.mjs.map +1 -1
- package/gradle-snapshot.d.mts +105 -0
- package/gradle-snapshot.d.mts.map +1 -0
- package/gradle-snapshot.d.ts +105 -0
- package/gradle-snapshot.d.ts.map +1 -0
- package/gradle-snapshot.js +73 -0
- package/gradle-snapshot.js.map +1 -0
- package/gradle-snapshot.mjs +64 -0
- package/gradle-snapshot.mjs.map +1 -0
- package/index.d.mts +2 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +2 -1
- package/index.d.ts.map +1 -1
- package/index.js +10 -2
- package/index.js.map +1 -1
- package/index.mjs +2 -1
- package/index.mjs.map +1 -1
- package/internal/instance-phase-stream.d.mts +34 -0
- package/internal/instance-phase-stream.d.mts.map +1 -0
- package/internal/instance-phase-stream.d.ts +34 -0
- package/internal/instance-phase-stream.d.ts.map +1 -0
- package/internal/instance-phase-stream.js +109 -0
- package/internal/instance-phase-stream.js.map +1 -0
- package/internal/instance-phase-stream.mjs +106 -0
- package/internal/instance-phase-stream.mjs.map +1 -0
- package/package.json +11 -1
- package/resources/analytics.d.mts +22 -2
- package/resources/analytics.d.mts.map +1 -1
- package/resources/analytics.d.ts +22 -2
- package/resources/analytics.d.ts.map +1 -1
- package/resources/analytics.js.map +1 -1
- package/resources/analytics.mjs.map +1 -1
- package/resources/gradle-instances.d.mts +27 -0
- package/resources/gradle-instances.d.mts.map +1 -1
- package/resources/gradle-instances.d.ts +27 -0
- package/resources/gradle-instances.d.ts.map +1 -1
- package/resources/gradle-instances.js +19 -0
- package/resources/gradle-instances.js.map +1 -1
- package/resources/gradle-instances.mjs +19 -0
- package/resources/gradle-instances.mjs.map +1 -1
- package/resources/index.d.mts +2 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +2 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +4 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -1
- package/resources/index.mjs.map +1 -1
- package/resources/macos-instances.d.mts +224 -0
- package/resources/macos-instances.d.mts.map +1 -0
- package/resources/macos-instances.d.ts +224 -0
- package/resources/macos-instances.d.ts.map +1 -0
- package/resources/macos-instances.js +51 -0
- package/resources/macos-instances.js.map +1 -0
- package/resources/macos-instances.mjs +47 -0
- package/resources/macos-instances.mjs.map +1 -0
- package/resources/snapshots.d.mts +19 -1
- package/resources/snapshots.d.mts.map +1 -1
- package/resources/snapshots.d.ts +19 -1
- package/resources/snapshots.d.ts.map +1 -1
- package/resources/snapshots.js +21 -1
- package/resources/snapshots.js.map +1 -1
- package/resources/snapshots.mjs +19 -0
- package/resources/snapshots.mjs.map +1 -1
- package/src/client.ts +20 -0
- package/src/gradle-snapshot.ts +194 -0
- package/src/index.ts +21 -0
- package/src/internal/instance-phase-stream.ts +138 -0
- package/src/resources/analytics.ts +22 -2
- package/src/resources/gradle-instances.ts +43 -0
- package/src/resources/index.ts +10 -0
- package/src/resources/macos-instances.ts +296 -0
- package/src/resources/snapshots.ts +39 -1
- package/src/version.ts +1 -1
- package/src/xcode-cache.ts +18 -111
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/xcode-cache.d.mts.map +1 -1
- package/xcode-cache.d.ts.map +1 -1
- package/xcode-cache.js +17 -99
- package/xcode-cache.js.map +1 -1
- package/xcode-cache.mjs +17 -99
- package/xcode-cache.mjs.map +1 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { followPhaseStream } from './internal/instance-phase-stream';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A disk snapshot of a Gradle build sandbox, restored after the instance is assigned and saved at
|
|
5
|
+
* termination. It keeps the synced project, Gradle's caches and wrapper distributions, ccache and
|
|
6
|
+
* Android SDK packages the build installed.
|
|
7
|
+
*/
|
|
8
|
+
export type GradleSnapshotConfig = {
|
|
9
|
+
/** Save under this organization-scoped key at termination. Defaults to restoring this key too. */
|
|
10
|
+
key?: string;
|
|
11
|
+
/** Restore in order, trying an exact match then the newest literal-prefix match for each entry. */
|
|
12
|
+
restoreKeys?: string[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* How far a restore got. `disabled` and `skipped` are not failures: they describe an ordinary
|
|
17
|
+
* cold instance, which is perfectly usable. Only `failed` means the workspace was supposed to be
|
|
18
|
+
* warm and something actually broke.
|
|
19
|
+
*/
|
|
20
|
+
export type GradleSnapshotRestorePhase =
|
|
21
|
+
| 'disabled'
|
|
22
|
+
| 'pending'
|
|
23
|
+
| 'downloading'
|
|
24
|
+
| 'extracting'
|
|
25
|
+
| 'restored'
|
|
26
|
+
| 'skipped'
|
|
27
|
+
| 'failed';
|
|
28
|
+
|
|
29
|
+
/** How far the save got. */
|
|
30
|
+
export type GradleSnapshotSavePhase =
|
|
31
|
+
| 'disabled'
|
|
32
|
+
| 'idle'
|
|
33
|
+
| 'requested'
|
|
34
|
+
| 'quiescing'
|
|
35
|
+
| 'archiving'
|
|
36
|
+
| 'uploading'
|
|
37
|
+
| 'published'
|
|
38
|
+
| 'skipped'
|
|
39
|
+
| 'failed'
|
|
40
|
+
| 'timed_out';
|
|
41
|
+
|
|
42
|
+
/** A restore key resolution passed over, so a miss is explainable rather than just a miss. */
|
|
43
|
+
export type GradleSnapshotSkippedKey = { key: string; reason: string };
|
|
44
|
+
|
|
45
|
+
export type GradleSnapshotRestoreStatus = {
|
|
46
|
+
phase: GradleSnapshotRestorePhase;
|
|
47
|
+
reason?: string;
|
|
48
|
+
message?: string;
|
|
49
|
+
/** Snapshot key the instance restores from. */
|
|
50
|
+
matchedKey?: string;
|
|
51
|
+
matchKind?: 'exact_hit' | 'prefix_hit';
|
|
52
|
+
skippedKeys?: GradleSnapshotSkippedKey[];
|
|
53
|
+
/** Whether the bytes came through the regional accelerator or directly from object storage. */
|
|
54
|
+
source?: 'tag' | 'direct';
|
|
55
|
+
bytes?: number;
|
|
56
|
+
uncompressedBytes?: number;
|
|
57
|
+
startedAt?: string;
|
|
58
|
+
finishedAt?: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type GradleSnapshotSaveStatus = {
|
|
62
|
+
phase: GradleSnapshotSavePhase;
|
|
63
|
+
reason?: string;
|
|
64
|
+
message?: string;
|
|
65
|
+
/** Snapshot key the save publishes under. */
|
|
66
|
+
key?: string;
|
|
67
|
+
bytes?: number;
|
|
68
|
+
uncompressedBytes?: number;
|
|
69
|
+
requestedAt?: string;
|
|
70
|
+
startedAt?: string;
|
|
71
|
+
finishedAt?: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type GradleInstanceSnapshot = {
|
|
75
|
+
config?: GradleSnapshotConfig;
|
|
76
|
+
restore: GradleSnapshotRestoreStatus;
|
|
77
|
+
save: GradleSnapshotSaveStatus;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** Which half of the snapshot lifecycle a follower waits on. */
|
|
81
|
+
export type GradleSnapshotSide = 'restore' | 'save';
|
|
82
|
+
|
|
83
|
+
export type GradleSnapshotFollowTarget = {
|
|
84
|
+
baseURL: string;
|
|
85
|
+
apiKey: string;
|
|
86
|
+
instanceId: string;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type GradleSnapshotFollowOptions = {
|
|
90
|
+
/** Defaults to 'restore'. */
|
|
91
|
+
side?: GradleSnapshotSide;
|
|
92
|
+
/** Called once per distinct state, including the state the stream opens with. */
|
|
93
|
+
onUpdate?: (snapshot: GradleInstanceSnapshot) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Called when the stream is open, and again after each reconnect. A caller that is about to
|
|
96
|
+
* cause the very transitions it wants to watch waits for this first, so it cannot race its
|
|
97
|
+
* own subscription.
|
|
98
|
+
*/
|
|
99
|
+
onOpen?: () => void;
|
|
100
|
+
/**
|
|
101
|
+
* How long to wait for a terminal phase. A restore is bounded at fifteen minutes and a save at
|
|
102
|
+
* ten server-side, so these are generous by design.
|
|
103
|
+
*/
|
|
104
|
+
timeoutMs?: number;
|
|
105
|
+
signal?: AbortSignal;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type GradleSnapshotFollowResult = {
|
|
109
|
+
/** The last state seen, terminal unless the stream ended first. */
|
|
110
|
+
snapshot: GradleInstanceSnapshot;
|
|
111
|
+
/** True if the instance disappeared before reaching a terminal phase. */
|
|
112
|
+
gone: boolean;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** The instance disappeared before reporting its disk snapshot state. */
|
|
116
|
+
export class GradleSnapshotGoneError extends Error {
|
|
117
|
+
constructor(readonly instanceId: string) {
|
|
118
|
+
super(`Instance ${instanceId} was gone before it reported any disk snapshot status`);
|
|
119
|
+
this.name = 'GradleSnapshotGoneError';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export class GradleSnapshotTimeoutError extends Error {
|
|
124
|
+
constructor(
|
|
125
|
+
readonly side: GradleSnapshotSide,
|
|
126
|
+
readonly timeoutMs: number,
|
|
127
|
+
readonly snapshot: GradleInstanceSnapshot | undefined,
|
|
128
|
+
) {
|
|
129
|
+
super(
|
|
130
|
+
`Timed out after ${Math.round(timeoutMs / 1000)}s waiting for the disk snapshot ${side} to finish` +
|
|
131
|
+
(snapshot ? ` (last phase: ${snapshot[side].phase})` : ''),
|
|
132
|
+
);
|
|
133
|
+
this.name = 'GradleSnapshotTimeoutError';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const DEFAULT_TIMEOUT_MS: Record<GradleSnapshotSide, number> = {
|
|
138
|
+
restore: 20 * 60 * 1000,
|
|
139
|
+
save: 12 * 60 * 1000,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** Phases past which nothing more will happen. */
|
|
143
|
+
export function isGradleRestoreTerminal(phase: GradleSnapshotRestorePhase): boolean {
|
|
144
|
+
return phase === 'disabled' || phase === 'restored' || phase === 'skipped' || phase === 'failed';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function isGradleSaveTerminal(phase: GradleSnapshotSavePhase): boolean {
|
|
148
|
+
return (
|
|
149
|
+
phase === 'disabled' ||
|
|
150
|
+
phase === 'published' ||
|
|
151
|
+
phase === 'skipped' ||
|
|
152
|
+
phase === 'failed' ||
|
|
153
|
+
phase === 'timed_out'
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function isGradleSnapshotTerminal(
|
|
158
|
+
snapshot: GradleInstanceSnapshot,
|
|
159
|
+
side: GradleSnapshotSide,
|
|
160
|
+
): boolean {
|
|
161
|
+
return side === 'restore' ?
|
|
162
|
+
isGradleRestoreTerminal(snapshot.restore.phase)
|
|
163
|
+
: isGradleSaveTerminal(snapshot.save.phase);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Follow the restore or the save until it ends, the instance disappears, or the wait times out. */
|
|
167
|
+
export async function followGradleSnapshot(
|
|
168
|
+
target: GradleSnapshotFollowTarget,
|
|
169
|
+
options: GradleSnapshotFollowOptions = {},
|
|
170
|
+
): Promise<GradleSnapshotFollowResult> {
|
|
171
|
+
const side = options.side ?? 'restore';
|
|
172
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS[side];
|
|
173
|
+
let base = target.baseURL;
|
|
174
|
+
while (base.endsWith('/')) base = base.slice(0, -1);
|
|
175
|
+
const result = await followPhaseStream<GradleInstanceSnapshot>({
|
|
176
|
+
url: `${base}/v1/gradle_instances/${encodeURIComponent(target.instanceId)}/snapshot`,
|
|
177
|
+
apiKey: target.apiKey,
|
|
178
|
+
instanceId: target.instanceId,
|
|
179
|
+
eventName: 'snapshot',
|
|
180
|
+
timeoutMs,
|
|
181
|
+
signal: options.signal,
|
|
182
|
+
onOpen: options.onOpen,
|
|
183
|
+
onUpdate: options.onUpdate,
|
|
184
|
+
transitionKey: (snapshot) =>
|
|
185
|
+
`${snapshot.restore.phase}/${snapshot.restore.reason ?? ''}|${snapshot.save.phase}/${
|
|
186
|
+
snapshot.save.reason ?? ''
|
|
187
|
+
}`,
|
|
188
|
+
isTerminal: (snapshot) => isGradleSnapshotTerminal(snapshot, side),
|
|
189
|
+
goneError: () => new GradleSnapshotGoneError(target.instanceId),
|
|
190
|
+
timeoutError: (last) => new GradleSnapshotTimeoutError(side, timeoutMs, last),
|
|
191
|
+
unreadableError: (err) => new Error(`Disk snapshot stream sent unreadable data: ${err}`),
|
|
192
|
+
});
|
|
193
|
+
return { snapshot: result.state, gone: result.gone };
|
|
194
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,9 @@ export { Limrun, type ClientOptions } from './client';
|
|
|
10
10
|
export {
|
|
11
11
|
XcodeSnapshots,
|
|
12
12
|
IOSSnapshots,
|
|
13
|
+
GradleSnapshots,
|
|
13
14
|
type XcodeSnapshot,
|
|
15
|
+
type GradleSnapshot,
|
|
14
16
|
type IOSSnapshot,
|
|
15
17
|
type SnapshotList,
|
|
16
18
|
type SnapshotListParams,
|
|
@@ -226,6 +228,25 @@ export {
|
|
|
226
228
|
type XcodeSnapshotFollowResult,
|
|
227
229
|
type XcodeSnapshotFollowTarget,
|
|
228
230
|
} from './xcode-snapshot';
|
|
231
|
+
export {
|
|
232
|
+
followGradleSnapshot,
|
|
233
|
+
isGradleRestoreTerminal,
|
|
234
|
+
isGradleSaveTerminal,
|
|
235
|
+
isGradleSnapshotTerminal,
|
|
236
|
+
GradleSnapshotGoneError,
|
|
237
|
+
GradleSnapshotTimeoutError,
|
|
238
|
+
type GradleSnapshotConfig,
|
|
239
|
+
type GradleInstanceSnapshot,
|
|
240
|
+
type GradleSnapshotRestoreStatus,
|
|
241
|
+
type GradleSnapshotSaveStatus,
|
|
242
|
+
type GradleSnapshotRestorePhase,
|
|
243
|
+
type GradleSnapshotSavePhase,
|
|
244
|
+
type GradleSnapshotSkippedKey,
|
|
245
|
+
type GradleSnapshotSide,
|
|
246
|
+
type GradleSnapshotFollowOptions,
|
|
247
|
+
type GradleSnapshotFollowResult,
|
|
248
|
+
type GradleSnapshotFollowTarget,
|
|
249
|
+
} from './gradle-snapshot';
|
|
229
250
|
export {
|
|
230
251
|
LimrunError,
|
|
231
252
|
APIError,
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { createEventSource, type EventSourceMessage } from 'eventsource-client';
|
|
2
|
+
|
|
3
|
+
import { nodeProxyTransport } from './proxy-transport';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* How to follow one instance's phase stream: an endpoint that answers JSON, or an event per
|
|
7
|
+
* phase change when asked for `text/event-stream`, and a `gone` event when the instance leaves.
|
|
8
|
+
* Xcode's cache and Gradle's snapshot both serve this shape.
|
|
9
|
+
*/
|
|
10
|
+
export type PhaseStreamOptions<T> = {
|
|
11
|
+
url: string;
|
|
12
|
+
apiKey: string;
|
|
13
|
+
instanceId: string;
|
|
14
|
+
/** The event carrying a state; `gone` is handled for every stream. */
|
|
15
|
+
eventName: string;
|
|
16
|
+
timeoutMs: number;
|
|
17
|
+
signal?: AbortSignal | undefined;
|
|
18
|
+
onOpen?: (() => void) | undefined;
|
|
19
|
+
onUpdate?: ((state: T) => void) | undefined;
|
|
20
|
+
/** Identifies a state, so a reconnect that replays the current one is not reported again. */
|
|
21
|
+
transitionKey: (state: T) => string;
|
|
22
|
+
isTerminal: (state: T) => boolean;
|
|
23
|
+
goneError: () => Error;
|
|
24
|
+
timeoutError: (last: T | undefined) => Error;
|
|
25
|
+
unreadableError: (err: unknown) => Error;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type PhaseStreamResult<T> = {
|
|
29
|
+
/** The last state seen, terminal unless the stream ended first. */
|
|
30
|
+
state: T;
|
|
31
|
+
/** True when the instance was collected before the phase went terminal. */
|
|
32
|
+
gone: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Follows an instance's phase stream until a state is terminal, the instance is collected, or the
|
|
37
|
+
* wait times out. The server emits on phase change only, so every callback is a real transition.
|
|
38
|
+
*/
|
|
39
|
+
export function followPhaseStream<T>(options: PhaseStreamOptions<T>): Promise<PhaseStreamResult<T>> {
|
|
40
|
+
const { url, apiKey } = options;
|
|
41
|
+
return new Promise<PhaseStreamResult<T>>((resolve, reject) => {
|
|
42
|
+
let last: T | undefined;
|
|
43
|
+
let lastKey = '';
|
|
44
|
+
let settled = false;
|
|
45
|
+
|
|
46
|
+
const finish = (fn: () => void) => {
|
|
47
|
+
if (settled) return;
|
|
48
|
+
settled = true;
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
51
|
+
try {
|
|
52
|
+
source.close();
|
|
53
|
+
} catch {
|
|
54
|
+
// A stream that never opened has nothing to close.
|
|
55
|
+
}
|
|
56
|
+
fn();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const timer = setTimeout(() => finish(() => reject(options.timeoutError(last))), options.timeoutMs);
|
|
60
|
+
const onAbort = () => finish(() => reject(options.signal?.reason ?? new Error('aborted')));
|
|
61
|
+
const resolveGone = () =>
|
|
62
|
+
finish(() => (last !== undefined ? resolve({ state: last, gone: true }) : reject(options.goneError())));
|
|
63
|
+
|
|
64
|
+
let confirming = false;
|
|
65
|
+
const confirmGone = () => {
|
|
66
|
+
if (confirming || settled) return;
|
|
67
|
+
confirming = true;
|
|
68
|
+
nodeProxyTransport
|
|
69
|
+
.fetch(url, {
|
|
70
|
+
headers: { Authorization: `Bearer ${apiKey}`, Accept: 'application/json' },
|
|
71
|
+
})
|
|
72
|
+
.then(async (res) => {
|
|
73
|
+
confirming = false;
|
|
74
|
+
if (res.status !== 404) {
|
|
75
|
+
await res.text().catch(() => undefined);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
resolveGone();
|
|
79
|
+
})
|
|
80
|
+
.catch(() => {
|
|
81
|
+
confirming = false;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// The endpoint answers from the region, which keeps the instance while it terminates and
|
|
86
|
+
// drops it once it is collected, so a 404 is the instance being over rather than a fault.
|
|
87
|
+
// Without this the client treats it as a connection to retry and follows a gone instance
|
|
88
|
+
// until the timeout, which is minutes of a command that looks hung and says nothing.
|
|
89
|
+
const fetchOrGone: typeof nodeProxyTransport.fetch = async (input, init) => {
|
|
90
|
+
const res = await nodeProxyTransport.fetch(input, init);
|
|
91
|
+
if (res.status === 404) resolveGone();
|
|
92
|
+
return res;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const source = createEventSource({
|
|
96
|
+
url,
|
|
97
|
+
fetch: fetchOrGone,
|
|
98
|
+
onConnect: () => options.onOpen?.(),
|
|
99
|
+
headers: {
|
|
100
|
+
Authorization: `Bearer ${apiKey}`,
|
|
101
|
+
Accept: 'text/event-stream',
|
|
102
|
+
},
|
|
103
|
+
onMessage: (message: EventSourceMessage) => {
|
|
104
|
+
if (message.event !== options.eventName && message.event !== 'gone') return;
|
|
105
|
+
let state: T;
|
|
106
|
+
try {
|
|
107
|
+
state = JSON.parse(typeof message.data === 'string' ? message.data : String(message.data));
|
|
108
|
+
} catch (err) {
|
|
109
|
+
finish(() => reject(options.unreadableError(err)));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
last = state;
|
|
113
|
+
if (message.event === 'gone') {
|
|
114
|
+
// The server also ends the stream this way when its own watch is cut short, which
|
|
115
|
+
// Kubernetes does routinely on a long one, so a request decides which it was. The
|
|
116
|
+
// client library reconnects on its own when the instance is in fact still there.
|
|
117
|
+
confirmGone();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// A reconnect replays the current state, which is not a transition.
|
|
121
|
+
const key = options.transitionKey(state);
|
|
122
|
+
if (key !== lastKey) {
|
|
123
|
+
lastKey = key;
|
|
124
|
+
options.onUpdate?.(state);
|
|
125
|
+
}
|
|
126
|
+
if (options.isTerminal(state)) {
|
|
127
|
+
finish(() => resolve({ state, gone: false }));
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (options.signal?.aborted) {
|
|
133
|
+
onAbort();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
@@ -86,7 +86,7 @@ export namespace AnalyticsInstancesResponse {
|
|
|
86
86
|
/**
|
|
87
87
|
* Platform name.
|
|
88
88
|
*/
|
|
89
|
-
platform: 'android' | 'ios' | 'xcode' | 'gradle';
|
|
89
|
+
platform: 'android' | 'ios' | 'xcode' | 'gradle' | 'macos';
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Actual runtime minutes before platform multiplier
|
|
@@ -225,6 +225,11 @@ export namespace AnalyticsResponse {
|
|
|
225
225
|
*/
|
|
226
226
|
ios: { [key: string]: Series.Ios };
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Map of region to analytics stats for macOS. Absent from servers that predate it.
|
|
230
|
+
*/
|
|
231
|
+
macos?: { [key: string]: Series.Macos };
|
|
232
|
+
|
|
228
233
|
/**
|
|
229
234
|
* RFC3339 timestamp for the start of the bucket in the requested timezone,
|
|
230
235
|
* including the local offset
|
|
@@ -331,6 +336,11 @@ export namespace AnalyticsResponse {
|
|
|
331
336
|
wallclockMinutes?: number;
|
|
332
337
|
}
|
|
333
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Analytics for macOS instances in a region, the same shape as Gradle's.
|
|
341
|
+
*/
|
|
342
|
+
export type Macos = Gradle;
|
|
343
|
+
|
|
334
344
|
/**
|
|
335
345
|
* Complete analytics for a specific region including billing breakdown
|
|
336
346
|
*/
|
|
@@ -617,7 +627,7 @@ export namespace AnalyticsResponse {
|
|
|
617
627
|
/**
|
|
618
628
|
* Platform name.
|
|
619
629
|
*/
|
|
620
|
-
platform: 'android' | 'ios' | 'xcode' | 'gradle';
|
|
630
|
+
platform: 'android' | 'ios' | 'xcode' | 'gradle' | 'macos';
|
|
621
631
|
|
|
622
632
|
/**
|
|
623
633
|
* Actual runtime minutes before platform multiplier
|
|
@@ -732,6 +742,11 @@ export namespace AnalyticsResponse {
|
|
|
732
742
|
*/
|
|
733
743
|
ios: { [key: string]: Summary.Ios };
|
|
734
744
|
|
|
745
|
+
/**
|
|
746
|
+
* Map of region to analytics stats for macOS. Absent from servers that predate it.
|
|
747
|
+
*/
|
|
748
|
+
macos?: { [key: string]: Summary.Macos };
|
|
749
|
+
|
|
735
750
|
/**
|
|
736
751
|
* Map of region to analytics stats for Xcode
|
|
737
752
|
*/
|
|
@@ -827,6 +842,11 @@ export namespace AnalyticsResponse {
|
|
|
827
842
|
wallclockMinutes?: number;
|
|
828
843
|
}
|
|
829
844
|
|
|
845
|
+
/**
|
|
846
|
+
* Analytics for macOS instances in a region, the same shape as Gradle's.
|
|
847
|
+
*/
|
|
848
|
+
export type Macos = Gradle;
|
|
849
|
+
|
|
830
850
|
/**
|
|
831
851
|
* Complete analytics for a specific region including billing breakdown
|
|
832
852
|
*/
|
|
@@ -7,6 +7,13 @@ import { Items, type ItemsParams, PagePromise } from '../core/pagination';
|
|
|
7
7
|
import { buildHeaders } from '../internal/headers';
|
|
8
8
|
import { RequestOptions } from '../internal/request-options';
|
|
9
9
|
import { path } from '../internal/utils/path';
|
|
10
|
+
import {
|
|
11
|
+
followGradleSnapshot,
|
|
12
|
+
type GradleInstanceSnapshot,
|
|
13
|
+
type GradleSnapshotConfig,
|
|
14
|
+
type GradleSnapshotFollowOptions,
|
|
15
|
+
type GradleSnapshotFollowResult,
|
|
16
|
+
} from '../gradle-snapshot';
|
|
10
17
|
|
|
11
18
|
export class GradleInstances extends APIResource {
|
|
12
19
|
/**
|
|
@@ -53,6 +60,26 @@ export class GradleInstances extends APIResource {
|
|
|
53
60
|
get(id: string, options?: RequestOptions): APIPromise<GradleInstance> {
|
|
54
61
|
return this._client.get(path`/v1/gradle_instances/${id}`, options);
|
|
55
62
|
}
|
|
63
|
+
|
|
64
|
+
/** Current disk snapshot configuration and status, including a save still running at termination. */
|
|
65
|
+
getSnapshot(id: string, options?: RequestOptions): APIPromise<GradleInstanceSnapshot> {
|
|
66
|
+
return this._client.get(path`/v1/gradle_instances/${id}/snapshot`, options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Set the key the instance saves under at termination. Set once: binding the same key again is
|
|
71
|
+
* accepted, a different one is rejected. Works on an instance created without a snapshot.
|
|
72
|
+
*/
|
|
73
|
+
bindSnapshotKey(id: string, key: string, options?: RequestOptions): APIPromise<GradleInstanceSnapshot> {
|
|
74
|
+
return this._client.put(path`/v1/gradle_instances/${id}/snapshot`, { body: { key }, ...options });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Follow the disk snapshot restore or save until it reaches a terminal phase. */
|
|
78
|
+
followSnapshot(id: string, options?: GradleSnapshotFollowOptions): Promise<GradleSnapshotFollowResult> {
|
|
79
|
+
const apiKey = this._client.apiKey;
|
|
80
|
+
if (!apiKey) throw new Error('Following disk snapshot status needs an API key on the client');
|
|
81
|
+
return followGradleSnapshot({ baseURL: this._client.baseURL, apiKey, instanceId: id }, options);
|
|
82
|
+
}
|
|
56
83
|
}
|
|
57
84
|
|
|
58
85
|
export type GradleInstancesItems = Items<GradleInstance>;
|
|
@@ -98,6 +125,8 @@ export namespace GradleInstance {
|
|
|
98
125
|
region: string;
|
|
99
126
|
|
|
100
127
|
hardTimeout?: string;
|
|
128
|
+
|
|
129
|
+
snapshot?: GradleSnapshotConfig;
|
|
101
130
|
}
|
|
102
131
|
|
|
103
132
|
export interface Status {
|
|
@@ -114,6 +143,14 @@ export namespace GradleInstance {
|
|
|
114
143
|
|
|
115
144
|
errorMessage?: string;
|
|
116
145
|
|
|
146
|
+
/** What happened to the instance's disk snapshot. getSnapshot() has the full status. */
|
|
147
|
+
snapshot?: {
|
|
148
|
+
/** The snapshot key the instance restores from. Absent when it starts cold. */
|
|
149
|
+
restoreKey?: string;
|
|
150
|
+
/** The save requested at termination. Absent until the instance is deleted. */
|
|
151
|
+
save?: { phase: string; reason?: string; message?: string };
|
|
152
|
+
};
|
|
153
|
+
|
|
117
154
|
/**
|
|
118
155
|
* Machine-readable reason for instance termination. Present when state is
|
|
119
156
|
* "terminating" or "terminated". New values may be added over time, so treat any
|
|
@@ -216,6 +253,12 @@ export namespace GradleInstanceCreateParams {
|
|
|
216
253
|
*/
|
|
217
254
|
jurisdiction?: 'us' | 'eu' | 'as';
|
|
218
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Disk snapshot to restore after assignment and save at termination. Omitted means an
|
|
258
|
+
* ordinary instance that restores and saves nothing.
|
|
259
|
+
*/
|
|
260
|
+
snapshot?: GradleSnapshotConfig;
|
|
261
|
+
|
|
219
262
|
/**
|
|
220
263
|
* Where the instance will be created. If not given, the region is decided based on
|
|
221
264
|
* scheduling clues (client location or IP) and availability.
|
package/src/resources/index.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
export {
|
|
4
4
|
XcodeSnapshots,
|
|
5
5
|
IOSSnapshots,
|
|
6
|
+
GradleSnapshots,
|
|
6
7
|
type XcodeSnapshot,
|
|
8
|
+
type GradleSnapshot,
|
|
7
9
|
type IOSSnapshot,
|
|
8
10
|
type SnapshotList,
|
|
9
11
|
type SnapshotListParams,
|
|
@@ -42,6 +44,14 @@ export {
|
|
|
42
44
|
type GradleInstanceListParams,
|
|
43
45
|
type GradleInstancesItems,
|
|
44
46
|
} from './gradle-instances';
|
|
47
|
+
export {
|
|
48
|
+
MacosInstances,
|
|
49
|
+
type MacosInstance,
|
|
50
|
+
type MacosInstanceUpdateParams,
|
|
51
|
+
type MacosInstanceCreateParams,
|
|
52
|
+
type MacosInstanceListParams,
|
|
53
|
+
type MacosInstancesItems,
|
|
54
|
+
} from './macos-instances';
|
|
45
55
|
export {
|
|
46
56
|
type IosInstance,
|
|
47
57
|
type IosInstanceUpdateParams,
|