Operations
The Operations class of @cubicle/sdk: its constructor, properties and methods.
Durable operations: exec, snapshot and restore requests, as cubicle.operations.
boxes.exec, boxes.snapshot and boxes.restore wait for their own operations; use this
to look one up by ID, or to wait again after a wait timed out.
Constructors
Constructor
new Operations(
transport,
pollIntervalMs,
pace
): Operations;Internal
Parameters
| Parameter | Type |
|---|---|
transport | Transport |
pollIntervalMs | number |
pace | Pace |
Returns
Operations
Methods
get()
get(operationId, options?): Promise<Operation>;One operation. Exec output is visible only to the caller that requested it.
Parameters
| Parameter | Type | Description |
|---|---|---|
operationId | string | The operation's ID. |
options? | { signal?: AbortSignal; } | - |
options.signal? | AbortSignal | Aborts the request. |
Returns
Promise<Operation>
Throws
CubicleApiError with code not_found when the caller cannot see it.
wait()
wait(operationId, options?): Promise<Operation>;Polls until the operation is done, and returns it. Rejects with CubicleOperationError
when it ends failed or unknown.
Parameters
| Parameter | Type | Description |
|---|---|---|
operationId | string | The operation's ID. |
options? | WaitOptions | timeoutMs (default 15 minutes) and signal. |
Returns
Promise<Operation>
The finished operation. For exec, result holds the ExecOutput.
Throws
CubicleOperationError when the operation ends failed or unknown.
Throws
CubicleTimeoutError when it is still running at the timeout.
Example
// Wait for a command that is still running, for example one started by an earlier run.
const operations = await box.listOperations()
const running = operations.find((operation) => operation.state === "running")
if (running) {
const done = await cubicle.operations.wait(running.id, { timeoutMs: 30 * 60_000 })
console.log(done.result)
}
