modal 0.5.0-dev.7 → 0.5.0
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/index.cjs +218 -88
- package/dist/index.d.cts +36 -28
- package/dist/index.d.ts +36 -28
- package/dist/index.js +217 -88
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -65,6 +65,7 @@ __export(index_exports, {
|
|
|
65
65
|
SecretService: () => SecretService,
|
|
66
66
|
Volume: () => Volume,
|
|
67
67
|
VolumeService: () => VolumeService,
|
|
68
|
+
checkForRenamedParams: () => checkForRenamedParams,
|
|
68
69
|
close: () => close,
|
|
69
70
|
initializeClient: () => initializeClient
|
|
70
71
|
});
|
|
@@ -43415,7 +43416,7 @@ function cborDecode(data) {
|
|
|
43415
43416
|
}
|
|
43416
43417
|
|
|
43417
43418
|
// src/invocation.ts
|
|
43418
|
-
var
|
|
43419
|
+
var outputsTimeoutMs = 55 * 1e3;
|
|
43419
43420
|
var ControlPlaneInvocation = class _ControlPlaneInvocation {
|
|
43420
43421
|
cpClient;
|
|
43421
43422
|
functionCallId;
|
|
@@ -43451,19 +43452,18 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
|
|
|
43451
43452
|
static fromFunctionCallId(client2, functionCallId) {
|
|
43452
43453
|
return new _ControlPlaneInvocation(client2.cpClient, functionCallId);
|
|
43453
43454
|
}
|
|
43454
|
-
async awaitOutput(
|
|
43455
|
+
async awaitOutput(timeoutMs) {
|
|
43455
43456
|
return await pollFunctionOutput(
|
|
43456
43457
|
this.cpClient,
|
|
43457
|
-
(
|
|
43458
|
-
|
|
43458
|
+
(timeoutMs2) => this.#getOutput(timeoutMs2),
|
|
43459
|
+
timeoutMs
|
|
43459
43460
|
);
|
|
43460
43461
|
}
|
|
43461
|
-
async #getOutput(
|
|
43462
|
+
async #getOutput(timeoutMs) {
|
|
43462
43463
|
const response = await this.cpClient.functionGetOutputs({
|
|
43463
43464
|
functionCallId: this.functionCallId,
|
|
43464
43465
|
maxValues: 1,
|
|
43465
|
-
timeout:
|
|
43466
|
-
// Backend needs seconds
|
|
43466
|
+
timeout: timeoutMs / 1e3,
|
|
43467
43467
|
lastEntryId: "0-0",
|
|
43468
43468
|
clearOnSuccess: true,
|
|
43469
43469
|
requestedAt: timeNowSeconds()
|
|
@@ -43517,18 +43517,18 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
|
|
|
43517
43517
|
attemptStartResponse.attemptToken
|
|
43518
43518
|
);
|
|
43519
43519
|
}
|
|
43520
|
-
async awaitOutput(
|
|
43520
|
+
async awaitOutput(timeoutMs) {
|
|
43521
43521
|
return await pollFunctionOutput(
|
|
43522
43522
|
this.cpClient,
|
|
43523
|
-
(
|
|
43524
|
-
|
|
43523
|
+
(timeoutMs2) => this.#getOutput(timeoutMs2),
|
|
43524
|
+
timeoutMs
|
|
43525
43525
|
);
|
|
43526
43526
|
}
|
|
43527
|
-
async #getOutput(
|
|
43527
|
+
async #getOutput(timeoutMs) {
|
|
43528
43528
|
const response = await this.ipClient.attemptAwait({
|
|
43529
43529
|
attemptToken: this.attemptToken,
|
|
43530
43530
|
requestedAt: timeNowSeconds(),
|
|
43531
|
-
timeoutSecs:
|
|
43531
|
+
timeoutSecs: timeoutMs / 1e3
|
|
43532
43532
|
});
|
|
43533
43533
|
return response.output;
|
|
43534
43534
|
}
|
|
@@ -43544,24 +43544,24 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
|
|
|
43544
43544
|
function timeNowSeconds() {
|
|
43545
43545
|
return Date.now() / 1e3;
|
|
43546
43546
|
}
|
|
43547
|
-
async function pollFunctionOutput(cpClient, getOutput,
|
|
43547
|
+
async function pollFunctionOutput(cpClient, getOutput, timeoutMs) {
|
|
43548
43548
|
const startTime = Date.now();
|
|
43549
|
-
let
|
|
43550
|
-
if (
|
|
43551
|
-
|
|
43549
|
+
let pollTimeoutMs = outputsTimeoutMs;
|
|
43550
|
+
if (timeoutMs !== void 0) {
|
|
43551
|
+
pollTimeoutMs = Math.min(timeoutMs, outputsTimeoutMs);
|
|
43552
43552
|
}
|
|
43553
43553
|
while (true) {
|
|
43554
|
-
const output = await getOutput(
|
|
43554
|
+
const output = await getOutput(pollTimeoutMs);
|
|
43555
43555
|
if (output) {
|
|
43556
43556
|
return await processResult(cpClient, output.result, output.dataFormat);
|
|
43557
43557
|
}
|
|
43558
|
-
if (
|
|
43559
|
-
const
|
|
43560
|
-
if (
|
|
43561
|
-
const message = `Timeout exceeded: ${
|
|
43558
|
+
if (timeoutMs !== void 0) {
|
|
43559
|
+
const remainingMs = timeoutMs - (Date.now() - startTime);
|
|
43560
|
+
if (remainingMs <= 0) {
|
|
43561
|
+
const message = `Timeout exceeded: ${timeoutMs}ms`;
|
|
43562
43562
|
throw new FunctionTimeoutError(message);
|
|
43563
43563
|
}
|
|
43564
|
-
|
|
43564
|
+
pollTimeoutMs = Math.min(outputsTimeoutMs, remainingMs);
|
|
43565
43565
|
}
|
|
43566
43566
|
}
|
|
43567
43567
|
}
|
|
@@ -43616,6 +43616,18 @@ function deserializeDataFormat(data, dataFormat) {
|
|
|
43616
43616
|
}
|
|
43617
43617
|
}
|
|
43618
43618
|
|
|
43619
|
+
// src/validation.ts
|
|
43620
|
+
function checkForRenamedParams(params, renames) {
|
|
43621
|
+
if (!params) return;
|
|
43622
|
+
for (const [oldName, newName] of Object.entries(renames)) {
|
|
43623
|
+
if (oldName in params) {
|
|
43624
|
+
throw new Error(
|
|
43625
|
+
`Parameter '${oldName}' has been renamed to '${newName}'.`
|
|
43626
|
+
);
|
|
43627
|
+
}
|
|
43628
|
+
}
|
|
43629
|
+
}
|
|
43630
|
+
|
|
43619
43631
|
// src/function_call.ts
|
|
43620
43632
|
var FunctionCallService = class {
|
|
43621
43633
|
#client;
|
|
@@ -43645,12 +43657,12 @@ var FunctionCall = class _FunctionCall {
|
|
|
43645
43657
|
}
|
|
43646
43658
|
/** Get the result of a FunctionCall, optionally waiting with a timeout. */
|
|
43647
43659
|
async get(params = {}) {
|
|
43648
|
-
|
|
43660
|
+
checkForRenamedParams(params, { timeout: "timeoutMs" });
|
|
43649
43661
|
const invocation = ControlPlaneInvocation.fromFunctionCallId(
|
|
43650
43662
|
this.#client || getDefaultClient(),
|
|
43651
43663
|
this.functionCallId
|
|
43652
43664
|
);
|
|
43653
|
-
return invocation.awaitOutput(
|
|
43665
|
+
return invocation.awaitOutput(params.timeoutMs);
|
|
43654
43666
|
}
|
|
43655
43667
|
/** Cancel a running FunctionCall. */
|
|
43656
43668
|
async cancel(params = {}) {
|
|
@@ -43770,7 +43782,7 @@ var Function_ = class {
|
|
|
43770
43782
|
async getCurrentStats() {
|
|
43771
43783
|
const resp = await this.#client.cpClient.functionGetCurrentStats(
|
|
43772
43784
|
{ functionId: this.functionId },
|
|
43773
|
-
{
|
|
43785
|
+
{ timeoutMs: 1e4 }
|
|
43774
43786
|
);
|
|
43775
43787
|
return {
|
|
43776
43788
|
backlog: resp.backlog,
|
|
@@ -43779,6 +43791,7 @@ var Function_ = class {
|
|
|
43779
43791
|
}
|
|
43780
43792
|
// Overrides the current autoscaler behavior for this Function.
|
|
43781
43793
|
async updateAutoscaler(params) {
|
|
43794
|
+
checkForRenamedParams(params, { scaledownWindow: "scaledownWindowMs" });
|
|
43782
43795
|
await this.#client.cpClient.functionUpdateSchedulingParams({
|
|
43783
43796
|
functionId: this.functionId,
|
|
43784
43797
|
warmPoolSizeOverride: 0,
|
|
@@ -43787,7 +43800,7 @@ var Function_ = class {
|
|
|
43787
43800
|
minContainers: params.minContainers,
|
|
43788
43801
|
maxContainers: params.maxContainers,
|
|
43789
43802
|
bufferContainers: params.bufferContainers,
|
|
43790
|
-
scaledownWindow: params.
|
|
43803
|
+
scaledownWindow: params.scaledownWindowMs !== void 0 ? Math.trunc(params.scaledownWindowMs / 1e3) : void 0
|
|
43791
43804
|
}
|
|
43792
43805
|
});
|
|
43793
43806
|
}
|
|
@@ -44139,10 +44152,58 @@ function mergeServiceOptions(base, diff) {
|
|
|
44139
44152
|
async function buildFunctionOptionsProto(options) {
|
|
44140
44153
|
if (!options) return void 0;
|
|
44141
44154
|
const o = options ?? {};
|
|
44155
|
+
checkForRenamedParams(o, {
|
|
44156
|
+
memory: "memoryMiB",
|
|
44157
|
+
memoryLimit: "memoryLimitMiB",
|
|
44158
|
+
scaledownWindow: "scaledownWindowMs",
|
|
44159
|
+
timeout: "timeoutMs"
|
|
44160
|
+
});
|
|
44142
44161
|
const gpuConfig = parseGpuConfig(o.gpu);
|
|
44143
|
-
|
|
44144
|
-
|
|
44145
|
-
|
|
44162
|
+
let milliCpu = void 0;
|
|
44163
|
+
let milliCpuMax = void 0;
|
|
44164
|
+
if (o.cpu === void 0 && o.cpuLimit !== void 0) {
|
|
44165
|
+
throw new Error("must also specify cpu when cpuLimit is specified");
|
|
44166
|
+
}
|
|
44167
|
+
if (o.cpu !== void 0) {
|
|
44168
|
+
if (o.cpu <= 0) {
|
|
44169
|
+
throw new Error(`cpu (${o.cpu}) must be a positive number`);
|
|
44170
|
+
}
|
|
44171
|
+
milliCpu = Math.trunc(1e3 * o.cpu);
|
|
44172
|
+
if (o.cpuLimit !== void 0) {
|
|
44173
|
+
if (o.cpuLimit < o.cpu) {
|
|
44174
|
+
throw new Error(
|
|
44175
|
+
`cpu (${o.cpu}) cannot be higher than cpuLimit (${o.cpuLimit})`
|
|
44176
|
+
);
|
|
44177
|
+
}
|
|
44178
|
+
milliCpuMax = Math.trunc(1e3 * o.cpuLimit);
|
|
44179
|
+
}
|
|
44180
|
+
}
|
|
44181
|
+
let memoryMb = void 0;
|
|
44182
|
+
let memoryMbMax = void 0;
|
|
44183
|
+
if (o.memoryMiB === void 0 && o.memoryLimitMiB !== void 0) {
|
|
44184
|
+
throw new Error(
|
|
44185
|
+
"must also specify memoryMiB when memoryLimitMiB is specified"
|
|
44186
|
+
);
|
|
44187
|
+
}
|
|
44188
|
+
if (o.memoryMiB !== void 0) {
|
|
44189
|
+
if (o.memoryMiB <= 0) {
|
|
44190
|
+
throw new Error(`memoryMiB (${o.memoryMiB}) must be a positive number`);
|
|
44191
|
+
}
|
|
44192
|
+
memoryMb = o.memoryMiB;
|
|
44193
|
+
if (o.memoryLimitMiB !== void 0) {
|
|
44194
|
+
if (o.memoryLimitMiB < o.memoryMiB) {
|
|
44195
|
+
throw new Error(
|
|
44196
|
+
`memoryMiB (${o.memoryMiB}) cannot be higher than memoryLimitMiB (${o.memoryLimitMiB})`
|
|
44197
|
+
);
|
|
44198
|
+
}
|
|
44199
|
+
memoryMbMax = o.memoryLimitMiB;
|
|
44200
|
+
}
|
|
44201
|
+
}
|
|
44202
|
+
const resources = milliCpu !== void 0 || milliCpuMax !== void 0 || memoryMb !== void 0 || memoryMbMax !== void 0 || gpuConfig ? {
|
|
44203
|
+
milliCpu,
|
|
44204
|
+
milliCpuMax,
|
|
44205
|
+
memoryMb,
|
|
44206
|
+
memoryMbMax,
|
|
44146
44207
|
gpuConfig
|
|
44147
44208
|
} : void 0;
|
|
44148
44209
|
const secretIds = (o.secrets || []).map((s) => s.secretId);
|
|
@@ -44159,13 +44220,15 @@ async function buildFunctionOptionsProto(options) {
|
|
|
44159
44220
|
initialDelayMs: parsedRetries.initialDelayMs,
|
|
44160
44221
|
maxDelayMs: parsedRetries.maxDelayMs
|
|
44161
44222
|
} : void 0;
|
|
44162
|
-
if (o.
|
|
44223
|
+
if (o.scaledownWindowMs !== void 0 && o.scaledownWindowMs % 1e3 !== 0) {
|
|
44163
44224
|
throw new Error(
|
|
44164
|
-
`
|
|
44225
|
+
`scaledownWindowMs must be a multiple of 1000ms, got ${o.scaledownWindowMs}`
|
|
44165
44226
|
);
|
|
44166
44227
|
}
|
|
44167
|
-
if (o.
|
|
44168
|
-
throw new Error(
|
|
44228
|
+
if (o.timeoutMs !== void 0 && o.timeoutMs % 1e3 !== 0) {
|
|
44229
|
+
throw new Error(
|
|
44230
|
+
`timeoutMs must be a multiple of 1000ms, got ${o.timeoutMs}`
|
|
44231
|
+
);
|
|
44169
44232
|
}
|
|
44170
44233
|
const functionOptions = FunctionOptions.create({
|
|
44171
44234
|
secretIds,
|
|
@@ -44176,8 +44239,8 @@ async function buildFunctionOptionsProto(options) {
|
|
|
44176
44239
|
retryPolicy,
|
|
44177
44240
|
concurrencyLimit: o.maxContainers,
|
|
44178
44241
|
bufferContainers: o.bufferContainers,
|
|
44179
|
-
taskIdleTimeoutSecs: o.
|
|
44180
|
-
timeoutSecs: o.
|
|
44242
|
+
taskIdleTimeoutSecs: o.scaledownWindowMs !== void 0 ? o.scaledownWindowMs / 1e3 : void 0,
|
|
44243
|
+
timeoutSecs: o.timeoutMs !== void 0 ? o.timeoutMs / 1e3 : void 0,
|
|
44181
44244
|
maxConcurrentInputs: o.maxConcurrentInputs,
|
|
44182
44245
|
targetConcurrentInputs: o.targetConcurrentInputs,
|
|
44183
44246
|
batchMaxSize: o.batchMaxSize,
|
|
@@ -44957,8 +45020,8 @@ var EphemeralHeartbeatManager = class {
|
|
|
44957
45020
|
};
|
|
44958
45021
|
|
|
44959
45022
|
// src/queue.ts
|
|
44960
|
-
var
|
|
44961
|
-
var
|
|
45023
|
+
var queueInitialPutBackoffMs = 100;
|
|
45024
|
+
var queueDefaultPartitionTtlMs = 24 * 3600 * 1e3;
|
|
44962
45025
|
var QueueService = class {
|
|
44963
45026
|
#client;
|
|
44964
45027
|
constructor(client2) {
|
|
@@ -45062,30 +45125,30 @@ var Queue = class _Queue {
|
|
|
45062
45125
|
allPartitions: params.all
|
|
45063
45126
|
});
|
|
45064
45127
|
}
|
|
45065
|
-
async #get(n, partition,
|
|
45128
|
+
async #get(n, partition, timeoutMs) {
|
|
45066
45129
|
const partitionKey = _Queue.#validatePartitionKey(partition);
|
|
45067
45130
|
const startTime = Date.now();
|
|
45068
|
-
let
|
|
45069
|
-
if (
|
|
45070
|
-
|
|
45131
|
+
let pollTimeoutMs = 5e4;
|
|
45132
|
+
if (timeoutMs !== void 0) {
|
|
45133
|
+
pollTimeoutMs = Math.min(pollTimeoutMs, timeoutMs);
|
|
45071
45134
|
}
|
|
45072
45135
|
while (true) {
|
|
45073
45136
|
const response = await this.#client.cpClient.queueGet({
|
|
45074
45137
|
queueId: this.queueId,
|
|
45075
45138
|
partitionKey,
|
|
45076
|
-
timeout:
|
|
45139
|
+
timeout: pollTimeoutMs / 1e3,
|
|
45077
45140
|
nValues: n
|
|
45078
45141
|
});
|
|
45079
45142
|
if (response.values && response.values.length > 0) {
|
|
45080
45143
|
return response.values.map((value) => loads(value));
|
|
45081
45144
|
}
|
|
45082
|
-
if (
|
|
45083
|
-
const
|
|
45084
|
-
if (
|
|
45085
|
-
const message = `Queue ${this.queueId} did not return values within ${
|
|
45145
|
+
if (timeoutMs !== void 0) {
|
|
45146
|
+
const remainingMs = timeoutMs - (Date.now() - startTime);
|
|
45147
|
+
if (remainingMs <= 0) {
|
|
45148
|
+
const message = `Queue ${this.queueId} did not return values within ${timeoutMs}ms.`;
|
|
45086
45149
|
throw new QueueEmptyError(message);
|
|
45087
45150
|
}
|
|
45088
|
-
|
|
45151
|
+
pollTimeoutMs = Math.min(pollTimeoutMs, remainingMs);
|
|
45089
45152
|
}
|
|
45090
45153
|
}
|
|
45091
45154
|
}
|
|
@@ -45093,35 +45156,37 @@ var Queue = class _Queue {
|
|
|
45093
45156
|
* Remove and return the next object from the Queue.
|
|
45094
45157
|
*
|
|
45095
45158
|
* By default, this will wait until at least one item is present in the Queue.
|
|
45096
|
-
* If `
|
|
45159
|
+
* If `timeoutMs` is set, raises `QueueEmptyError` if no items are available
|
|
45097
45160
|
* within that timeout in milliseconds.
|
|
45098
45161
|
*/
|
|
45099
45162
|
async get(params = {}) {
|
|
45100
|
-
|
|
45163
|
+
checkForRenamedParams(params, { timeout: "timeoutMs" });
|
|
45164
|
+
const values = await this.#get(1, params.partition, params.timeoutMs);
|
|
45101
45165
|
return values[0];
|
|
45102
45166
|
}
|
|
45103
45167
|
/**
|
|
45104
45168
|
* Remove and return up to `n` objects from the Queue.
|
|
45105
45169
|
*
|
|
45106
45170
|
* By default, this will wait until at least one item is present in the Queue.
|
|
45107
|
-
* If `
|
|
45171
|
+
* If `timeoutMs` is set, raises `QueueEmptyError` if no items are available
|
|
45108
45172
|
* within that timeout in milliseconds.
|
|
45109
45173
|
*/
|
|
45110
45174
|
async getMany(n, params = {}) {
|
|
45111
|
-
|
|
45175
|
+
checkForRenamedParams(params, { timeout: "timeoutMs" });
|
|
45176
|
+
return await this.#get(n, params.partition, params.timeoutMs);
|
|
45112
45177
|
}
|
|
45113
|
-
async #put(values,
|
|
45178
|
+
async #put(values, timeoutMs, partition, partitionTtlMs) {
|
|
45114
45179
|
const valuesEncoded = values.map((v) => dumps(v));
|
|
45115
45180
|
const partitionKey = _Queue.#validatePartitionKey(partition);
|
|
45116
|
-
let delay =
|
|
45117
|
-
const deadline =
|
|
45181
|
+
let delay = queueInitialPutBackoffMs;
|
|
45182
|
+
const deadline = timeoutMs ? Date.now() + timeoutMs : void 0;
|
|
45118
45183
|
while (true) {
|
|
45119
45184
|
try {
|
|
45120
45185
|
await this.#client.cpClient.queuePut({
|
|
45121
45186
|
queueId: this.queueId,
|
|
45122
45187
|
values: valuesEncoded,
|
|
45123
45188
|
partitionKey,
|
|
45124
|
-
partitionTtlSeconds: (
|
|
45189
|
+
partitionTtlSeconds: (partitionTtlMs || queueDefaultPartitionTtlMs) / 1e3
|
|
45125
45190
|
});
|
|
45126
45191
|
break;
|
|
45127
45192
|
} catch (e) {
|
|
@@ -45144,25 +45209,38 @@ var Queue = class _Queue {
|
|
|
45144
45209
|
* Add an item to the end of the Queue.
|
|
45145
45210
|
*
|
|
45146
45211
|
* If the Queue is full, this will retry with exponential backoff until the
|
|
45147
|
-
* provided `
|
|
45212
|
+
* provided `timeoutMs` is reached, or indefinitely if `timeoutMs` is not set.
|
|
45148
45213
|
* Raises {@link QueueFullError} if the Queue is still full after the timeout.
|
|
45149
45214
|
*/
|
|
45150
45215
|
async put(v, params = {}) {
|
|
45151
|
-
|
|
45216
|
+
checkForRenamedParams(params, {
|
|
45217
|
+
timeout: "timeoutMs",
|
|
45218
|
+
partitionTtl: "partitionTtlMs"
|
|
45219
|
+
});
|
|
45220
|
+
await this.#put(
|
|
45221
|
+
[v],
|
|
45222
|
+
params.timeoutMs,
|
|
45223
|
+
params.partition,
|
|
45224
|
+
params.partitionTtlMs
|
|
45225
|
+
);
|
|
45152
45226
|
}
|
|
45153
45227
|
/**
|
|
45154
45228
|
* Add several items to the end of the Queue.
|
|
45155
45229
|
*
|
|
45156
45230
|
* If the Queue is full, this will retry with exponential backoff until the
|
|
45157
|
-
* provided `
|
|
45231
|
+
* provided `timeoutMs` is reached, or indefinitely if `timeoutMs` is not set.
|
|
45158
45232
|
* Raises {@link QueueFullError} if the Queue is still full after the timeout.
|
|
45159
45233
|
*/
|
|
45160
45234
|
async putMany(values, params = {}) {
|
|
45235
|
+
checkForRenamedParams(params, {
|
|
45236
|
+
timeout: "timeoutMs",
|
|
45237
|
+
partitionTtl: "partitionTtlMs"
|
|
45238
|
+
});
|
|
45161
45239
|
await this.#put(
|
|
45162
45240
|
values,
|
|
45163
|
-
params.
|
|
45241
|
+
params.timeoutMs,
|
|
45164
45242
|
params.partition,
|
|
45165
|
-
params.
|
|
45243
|
+
params.partitionTtlMs
|
|
45166
45244
|
);
|
|
45167
45245
|
}
|
|
45168
45246
|
/** Return the number of objects in the Queue. */
|
|
@@ -45181,20 +45259,21 @@ var Queue = class _Queue {
|
|
|
45181
45259
|
}
|
|
45182
45260
|
/** Iterate through items in a Queue without mutation. */
|
|
45183
45261
|
async *iterate(params = {}) {
|
|
45184
|
-
|
|
45262
|
+
checkForRenamedParams(params, { itemPollTimeout: "itemPollTimeoutMs" });
|
|
45263
|
+
const { partition, itemPollTimeoutMs = 0 } = params;
|
|
45185
45264
|
let lastEntryId = void 0;
|
|
45186
45265
|
const validatedPartitionKey = _Queue.#validatePartitionKey(partition);
|
|
45187
|
-
let fetchDeadline = Date.now() +
|
|
45188
|
-
const
|
|
45266
|
+
let fetchDeadline = Date.now() + itemPollTimeoutMs;
|
|
45267
|
+
const maxPollDurationMs = 3e4;
|
|
45189
45268
|
while (true) {
|
|
45190
|
-
const
|
|
45269
|
+
const pollDurationMs = Math.max(
|
|
45191
45270
|
0,
|
|
45192
|
-
Math.min(
|
|
45271
|
+
Math.min(maxPollDurationMs, fetchDeadline - Date.now())
|
|
45193
45272
|
);
|
|
45194
45273
|
const request = {
|
|
45195
45274
|
queueId: this.queueId,
|
|
45196
45275
|
partitionKey: validatedPartitionKey,
|
|
45197
|
-
itemPollTimeout:
|
|
45276
|
+
itemPollTimeout: pollDurationMs / 1e3,
|
|
45198
45277
|
lastEntryId: lastEntryId || ""
|
|
45199
45278
|
};
|
|
45200
45279
|
const response = await this.#client.cpClient.queueNextItems(request);
|
|
@@ -45203,7 +45282,7 @@ var Queue = class _Queue {
|
|
|
45203
45282
|
yield loads(item.value);
|
|
45204
45283
|
lastEntryId = item.entryId;
|
|
45205
45284
|
}
|
|
45206
|
-
fetchDeadline = Date.now() +
|
|
45285
|
+
fetchDeadline = Date.now() + itemPollTimeoutMs;
|
|
45207
45286
|
} else if (Date.now() > fetchDeadline) {
|
|
45208
45287
|
break;
|
|
45209
45288
|
}
|
|
@@ -45490,15 +45569,21 @@ function cloudBucketMountToProto(mount, mountPath) {
|
|
|
45490
45569
|
|
|
45491
45570
|
// src/sandbox.ts
|
|
45492
45571
|
async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
|
|
45572
|
+
checkForRenamedParams(params, {
|
|
45573
|
+
memory: "memoryMiB",
|
|
45574
|
+
memoryLimit: "memoryLimitMiB",
|
|
45575
|
+
timeout: "timeoutMs",
|
|
45576
|
+
idleTimeout: "idleTimeoutMs"
|
|
45577
|
+
});
|
|
45493
45578
|
const gpuConfig = parseGpuConfig(params.gpu);
|
|
45494
|
-
if (params.
|
|
45579
|
+
if (params.timeoutMs && params.timeoutMs % 1e3 !== 0) {
|
|
45495
45580
|
throw new Error(
|
|
45496
|
-
`
|
|
45581
|
+
`timeoutMs must be a multiple of 1000ms, got ${params.timeoutMs}`
|
|
45497
45582
|
);
|
|
45498
45583
|
}
|
|
45499
|
-
if (params.
|
|
45584
|
+
if (params.idleTimeoutMs && params.idleTimeoutMs % 1e3 !== 0) {
|
|
45500
45585
|
throw new Error(
|
|
45501
|
-
`
|
|
45586
|
+
`idleTimeoutMs must be a multiple of 1000ms, got ${params.idleTimeoutMs}`
|
|
45502
45587
|
);
|
|
45503
45588
|
}
|
|
45504
45589
|
if (params.workdir && !params.workdir.startsWith("/")) {
|
|
@@ -45569,20 +45654,63 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
|
|
|
45569
45654
|
if (params.pty) {
|
|
45570
45655
|
ptyInfo = defaultSandboxPTYInfo();
|
|
45571
45656
|
}
|
|
45657
|
+
let milliCpu = void 0;
|
|
45658
|
+
let milliCpuMax = void 0;
|
|
45659
|
+
if (params.cpu === void 0 && params.cpuLimit !== void 0) {
|
|
45660
|
+
throw new Error("must also specify cpu when cpuLimit is specified");
|
|
45661
|
+
}
|
|
45662
|
+
if (params.cpu !== void 0) {
|
|
45663
|
+
if (params.cpu <= 0) {
|
|
45664
|
+
throw new Error(`cpu (${params.cpu}) must be a positive number`);
|
|
45665
|
+
}
|
|
45666
|
+
milliCpu = Math.trunc(1e3 * params.cpu);
|
|
45667
|
+
if (params.cpuLimit !== void 0) {
|
|
45668
|
+
if (params.cpuLimit < params.cpu) {
|
|
45669
|
+
throw new Error(
|
|
45670
|
+
`cpu (${params.cpu}) cannot be higher than cpuLimit (${params.cpuLimit})`
|
|
45671
|
+
);
|
|
45672
|
+
}
|
|
45673
|
+
milliCpuMax = Math.trunc(1e3 * params.cpuLimit);
|
|
45674
|
+
}
|
|
45675
|
+
}
|
|
45676
|
+
let memoryMb = void 0;
|
|
45677
|
+
let memoryMbMax = void 0;
|
|
45678
|
+
if (params.memoryMiB === void 0 && params.memoryLimitMiB !== void 0) {
|
|
45679
|
+
throw new Error(
|
|
45680
|
+
"must also specify memoryMiB when memoryLimitMiB is specified"
|
|
45681
|
+
);
|
|
45682
|
+
}
|
|
45683
|
+
if (params.memoryMiB !== void 0) {
|
|
45684
|
+
if (params.memoryMiB <= 0) {
|
|
45685
|
+
throw new Error(
|
|
45686
|
+
`the memoryMiB request (${params.memoryMiB}) must be a positive number`
|
|
45687
|
+
);
|
|
45688
|
+
}
|
|
45689
|
+
memoryMb = params.memoryMiB;
|
|
45690
|
+
if (params.memoryLimitMiB !== void 0) {
|
|
45691
|
+
if (params.memoryLimitMiB < params.memoryMiB) {
|
|
45692
|
+
throw new Error(
|
|
45693
|
+
`the memoryMiB request (${params.memoryMiB}) cannot be higher than memoryLimitMiB (${params.memoryLimitMiB})`
|
|
45694
|
+
);
|
|
45695
|
+
}
|
|
45696
|
+
memoryMbMax = params.memoryLimitMiB;
|
|
45697
|
+
}
|
|
45698
|
+
}
|
|
45572
45699
|
return SandboxCreateRequest.create({
|
|
45573
45700
|
appId,
|
|
45574
45701
|
definition: {
|
|
45575
45702
|
// Sleep default is implicit in image builder version <=2024.10
|
|
45576
45703
|
entrypointArgs: params.command ?? ["sleep", "48h"],
|
|
45577
45704
|
imageId,
|
|
45578
|
-
timeoutSecs: params.
|
|
45579
|
-
idleTimeoutSecs: params.
|
|
45705
|
+
timeoutSecs: params.timeoutMs != void 0 ? params.timeoutMs / 1e3 : 600,
|
|
45706
|
+
idleTimeoutSecs: params.idleTimeoutMs != void 0 ? params.idleTimeoutMs / 1e3 : void 0,
|
|
45580
45707
|
workdir: params.workdir ?? void 0,
|
|
45581
45708
|
networkAccess,
|
|
45582
45709
|
resources: {
|
|
45583
|
-
|
|
45584
|
-
|
|
45585
|
-
memoryMb
|
|
45710
|
+
milliCpu,
|
|
45711
|
+
milliCpuMax,
|
|
45712
|
+
memoryMb,
|
|
45713
|
+
memoryMbMax,
|
|
45586
45714
|
gpuConfig
|
|
45587
45715
|
},
|
|
45588
45716
|
volumeMounts,
|
|
@@ -45757,6 +45885,7 @@ function defaultSandboxPTYInfo() {
|
|
|
45757
45885
|
});
|
|
45758
45886
|
}
|
|
45759
45887
|
async function buildContainerExecRequestProto(taskId, command, params) {
|
|
45888
|
+
checkForRenamedParams(params, { timeout: "timeoutMs" });
|
|
45760
45889
|
const secretIds = (params?.secrets || []).map((secret) => secret.secretId);
|
|
45761
45890
|
let ptyInfo;
|
|
45762
45891
|
if (params?.pty) {
|
|
@@ -45766,7 +45895,7 @@ async function buildContainerExecRequestProto(taskId, command, params) {
|
|
|
45766
45895
|
taskId,
|
|
45767
45896
|
command,
|
|
45768
45897
|
workdir: params?.workdir,
|
|
45769
|
-
timeoutSecs: params?.
|
|
45898
|
+
timeoutSecs: params?.timeoutMs ? params.timeoutMs / 1e3 : 0,
|
|
45770
45899
|
secretIds,
|
|
45771
45900
|
ptyInfo
|
|
45772
45901
|
});
|
|
@@ -45934,14 +46063,13 @@ var Sandbox2 = class _Sandbox {
|
|
|
45934
46063
|
*
|
|
45935
46064
|
* @returns A dictionary of {@link Tunnel} objects which are keyed by the container port.
|
|
45936
46065
|
*/
|
|
45937
|
-
async tunnels(
|
|
46066
|
+
async tunnels(timeoutMs = 5e4) {
|
|
45938
46067
|
if (this.#tunnels) {
|
|
45939
46068
|
return this.#tunnels;
|
|
45940
46069
|
}
|
|
45941
46070
|
const resp = await this.#client.cpClient.sandboxGetTunnels({
|
|
45942
46071
|
sandboxId: this.sandboxId,
|
|
45943
|
-
timeout:
|
|
45944
|
-
// Convert to seconds
|
|
46072
|
+
timeout: timeoutMs / 1e3
|
|
45945
46073
|
});
|
|
45946
46074
|
if (resp.result?.status === 4 /* GENERIC_STATUS_TIMEOUT */) {
|
|
45947
46075
|
throw new SandboxTimeoutError();
|
|
@@ -45962,13 +46090,13 @@ var Sandbox2 = class _Sandbox {
|
|
|
45962
46090
|
*
|
|
45963
46091
|
* Returns an {@link Image} object which can be used to spawn a new Sandbox with the same filesystem.
|
|
45964
46092
|
*
|
|
45965
|
-
* @param
|
|
46093
|
+
* @param timeoutMs - Timeout for the snapshot operation in milliseconds
|
|
45966
46094
|
* @returns Promise that resolves to an {@link Image}
|
|
45967
46095
|
*/
|
|
45968
|
-
async snapshotFilesystem(
|
|
46096
|
+
async snapshotFilesystem(timeoutMs = 55e3) {
|
|
45969
46097
|
const resp = await this.#client.cpClient.sandboxSnapshotFs({
|
|
45970
46098
|
sandboxId: this.sandboxId,
|
|
45971
|
-
timeout:
|
|
46099
|
+
timeout: timeoutMs / 1e3
|
|
45972
46100
|
});
|
|
45973
46101
|
if (resp.result?.status !== 1 /* GENERIC_STATUS_SUCCESS */) {
|
|
45974
46102
|
throw new Error(
|
|
@@ -46420,7 +46548,7 @@ var AuthTokenManager = class {
|
|
|
46420
46548
|
|
|
46421
46549
|
// src/version.ts
|
|
46422
46550
|
function getSDKVersion() {
|
|
46423
|
-
return true ? "0.5.0
|
|
46551
|
+
return true ? "0.5.0" : "0.0.0";
|
|
46424
46552
|
}
|
|
46425
46553
|
|
|
46426
46554
|
// src/client.ts
|
|
@@ -46441,6 +46569,7 @@ var ModalClient = class {
|
|
|
46441
46569
|
ipClients;
|
|
46442
46570
|
authTokenManager = null;
|
|
46443
46571
|
constructor(params) {
|
|
46572
|
+
checkForRenamedParams(params, { timeout: "timeoutMs" });
|
|
46444
46573
|
const baseProfile = getProfile(process.env["MODAL_PROFILE"]);
|
|
46445
46574
|
this.profile = {
|
|
46446
46575
|
...baseProfile,
|
|
@@ -46534,10 +46663,10 @@ var ModalClient = class {
|
|
|
46534
46663
|
}
|
|
46535
46664
|
};
|
|
46536
46665
|
var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
|
|
46537
|
-
if (!options.
|
|
46666
|
+
if (!options.timeoutMs || options.signal?.aborted) {
|
|
46538
46667
|
return yield* call.next(call.request, options);
|
|
46539
46668
|
}
|
|
46540
|
-
const {
|
|
46669
|
+
const { timeoutMs, signal: origSignal, ...restOptions } = options;
|
|
46541
46670
|
const abortController = new AbortController();
|
|
46542
46671
|
const abortListener = () => abortController.abort();
|
|
46543
46672
|
origSignal?.addEventListener("abort", abortListener);
|
|
@@ -46545,7 +46674,7 @@ var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
|
|
|
46545
46674
|
const timer = setTimeout(() => {
|
|
46546
46675
|
timedOut = true;
|
|
46547
46676
|
abortController.abort();
|
|
46548
|
-
},
|
|
46677
|
+
}, timeoutMs);
|
|
46549
46678
|
try {
|
|
46550
46679
|
return yield* call.next(call.request, {
|
|
46551
46680
|
...restOptions,
|
|
@@ -46558,7 +46687,7 @@ var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
|
|
|
46558
46687
|
throw new import_nice_grpc10.ClientError(
|
|
46559
46688
|
call.method.path,
|
|
46560
46689
|
import_nice_grpc10.Status.DEADLINE_EXCEEDED,
|
|
46561
|
-
`Timed out after ${
|
|
46690
|
+
`Timed out after ${timeoutMs}ms`
|
|
46562
46691
|
);
|
|
46563
46692
|
}
|
|
46564
46693
|
}
|
|
@@ -46785,6 +46914,7 @@ var App2 = class {
|
|
|
46785
46914
|
SecretService,
|
|
46786
46915
|
Volume,
|
|
46787
46916
|
VolumeService,
|
|
46917
|
+
checkForRenamedParams,
|
|
46788
46918
|
close,
|
|
46789
46919
|
initializeClient
|
|
46790
46920
|
});
|