@runblackcat/sdk 0.1.0-alpha.88 → 0.1.0-alpha.89
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 +6 -0
- package/package.json +1 -1
- package/sdk/dist/index.d.ts +13 -4
- package/sdk/dist/index.js +7 -4
package/README.md
CHANGED
|
@@ -168,6 +168,12 @@ GET /v1/sandboxes/acquisitions/{id} -> 202 pending … -> 200 {"state":"p
|
|
|
168
168
|
POST /v1/sandboxes/{id}/renew {ttl_secs} -> 200 {"expires_at":…, "renewable_until":…}
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
Add `?wait_secs=N` (held at most 55 s) to the create or the lookup to have the gateway
|
|
172
|
+
hold a still-pending claim and answer as soon as it is placed or fails; the
|
|
173
|
+
placed receipt carries `ports`, so there is nothing to poll and no second call.
|
|
174
|
+
A claim still pending when the hold ends is answered `pending`; ask again. It
|
|
175
|
+
does not apply to a `count` batch: wait on each member by `request_id`.
|
|
176
|
+
|
|
171
177
|
To start many identical sandboxes, add `"count": N` (1 to 1000) to the create.
|
|
172
178
|
`request_id` then names the batch and member `i` is `request_id.i`. The whole batch
|
|
173
179
|
is recorded in one durable transaction and answered `202` at once, with no
|
package/package.json
CHANGED
package/sdk/dist/index.d.ts
CHANGED
|
@@ -369,8 +369,8 @@ export type CreateCapacityReservationInput = ({
|
|
|
369
369
|
* ordinary work; a sandbox create naming it waits for one of its slots. */
|
|
370
370
|
placement?: "shared" | "dedicated";
|
|
371
371
|
/** With `placement: "dedicated"`, the provider shape to launch: an exact
|
|
372
|
-
* shape or a family (`c7i`)
|
|
373
|
-
* planner chooses. */
|
|
372
|
+
* shape or a family (`c7i`) the fleet can launch (direct EC2: the config's
|
|
373
|
+
* instance_types). Absent: the planner chooses. */
|
|
374
374
|
shape?: string;
|
|
375
375
|
/** Stable retry key, at most 107 ASCII letters, digits, `_` or `-`. */
|
|
376
376
|
idempotency_key?: string;
|
|
@@ -406,6 +406,15 @@ export interface CapacityReservation {
|
|
|
406
406
|
/** When the capacity must be ready (epoch milliseconds), or null. */
|
|
407
407
|
needed_by: number | null;
|
|
408
408
|
}
|
|
409
|
+
export interface WaitOptions {
|
|
410
|
+
/**
|
|
411
|
+
* Have the gateway hold a still-pending claim for up to this many seconds
|
|
412
|
+
* and answer as soon as it is placed or fails, with its ports, instead of
|
|
413
|
+
* answering `pending` at once. The gateway holds at most 55 seconds. A claim
|
|
414
|
+
* still pending after the hold is returned as `pending`; ask again.
|
|
415
|
+
*/
|
|
416
|
+
wait_secs?: number;
|
|
417
|
+
}
|
|
409
418
|
/**
|
|
410
419
|
* Response returned by POST /v1/sandboxes (the gateway has no template field).
|
|
411
420
|
* The gateway sends a `failed` receipt with HTTP 409, so `create` and
|
|
@@ -872,7 +881,7 @@ declare class SandboxesResource {
|
|
|
872
881
|
* recover a lost response. A pending receipt is not an executable sandbox;
|
|
873
882
|
* no automatic retry, new ID, or replacement allocation is synthesized here.
|
|
874
883
|
*/
|
|
875
|
-
create(input: CreateSandboxInput): Promise<CreateSandboxResponse>;
|
|
884
|
+
create(input: CreateSandboxInput, options?: WaitOptions): Promise<CreateSandboxResponse>;
|
|
876
885
|
/**
|
|
877
886
|
* Create `count` identical sandboxes under one request ID. Resolves as soon
|
|
878
887
|
* as the whole batch is durably recorded; nothing waits on a restore.
|
|
@@ -882,7 +891,7 @@ declare class SandboxesResource {
|
|
|
882
891
|
createBatch(input: CreateSandboxBatchInput): Promise<SandboxBatchResponse>;
|
|
883
892
|
/** Counts by state and every member of a batch created with `createBatch`. */
|
|
884
893
|
batch(requestId: string): Promise<SandboxBatchResponse>;
|
|
885
|
-
acquisition(requestId: string): Promise<CreateSandboxResponse>;
|
|
894
|
+
acquisition(requestId: string, options?: WaitOptions): Promise<CreateSandboxResponse>;
|
|
886
895
|
/**
|
|
887
896
|
* Fence an acquisition request ID before its create is recorded, or destroy
|
|
888
897
|
* the allocation when the create has already won.
|
package/sdk/dist/index.js
CHANGED
|
@@ -21,6 +21,9 @@ var BLACKCAT_ERROR_CODES = {
|
|
|
21
21
|
function withTemplate(input) {
|
|
22
22
|
return { ...input, template: input.template ?? "default" };
|
|
23
23
|
}
|
|
24
|
+
function waitQuery({ wait_secs }) {
|
|
25
|
+
return wait_secs === undefined ? "" : `?wait_secs=${wait_secs}`;
|
|
26
|
+
}
|
|
24
27
|
|
|
25
28
|
class BlackcatApiError extends Error {
|
|
26
29
|
status;
|
|
@@ -455,8 +458,8 @@ class SandboxesResource {
|
|
|
455
458
|
list() {
|
|
456
459
|
return this.client.json("GET", "/v1/sandboxes", undefined, "token");
|
|
457
460
|
}
|
|
458
|
-
async create(input) {
|
|
459
|
-
return parseCreateSandboxResponse(await this.client.json("POST",
|
|
461
|
+
async create(input, options = {}) {
|
|
462
|
+
return parseCreateSandboxResponse(await this.client.json("POST", `/v1/sandboxes${waitQuery(options)}`, withTemplate(input), "token", false), input.request_id);
|
|
460
463
|
}
|
|
461
464
|
async createBatch(input) {
|
|
462
465
|
return parseSandboxBatch(await this.client.json("POST", "/v1/sandboxes", withTemplate(input), "token", false), input.request_id);
|
|
@@ -464,8 +467,8 @@ class SandboxesResource {
|
|
|
464
467
|
async batch(requestId) {
|
|
465
468
|
return parseSandboxBatch(await this.client.json("GET", `/v1/sandboxes/batches/${pathSegment(requestId)}`, undefined, "token"), requestId);
|
|
466
469
|
}
|
|
467
|
-
async acquisition(requestId) {
|
|
468
|
-
return parseCreateSandboxResponse(await this.client.json("GET", `/v1/sandboxes/acquisitions/${pathSegment(requestId)}`, undefined, "token"), requestId);
|
|
470
|
+
async acquisition(requestId, options = {}) {
|
|
471
|
+
return parseCreateSandboxResponse(await this.client.json("GET", `/v1/sandboxes/acquisitions/${pathSegment(requestId)}${waitQuery(options)}`, undefined, "token", options.wait_secs === undefined ? undefined : false), requestId);
|
|
469
472
|
}
|
|
470
473
|
async cancelAcquisition(requestId) {
|
|
471
474
|
return parseCreateSandboxResponse(await this.client.json("DELETE", `/v1/sandboxes/acquisitions/${pathSegment(requestId)}`, undefined, "token"), requestId);
|