@decocms/sandbox-controller 0.12.3 → 0.12.5
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.d.ts +1 -0
- package/dist/index.js +37 -29
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3889,6 +3889,7 @@ declare class FreestyleSandboxProvider implements SandboxProvider {
|
|
|
3889
3889
|
* server's own traffic. Returns the handles paused; never throws.
|
|
3890
3890
|
*/
|
|
3891
3891
|
pauseIdle(): Promise<string[]>;
|
|
3892
|
+
private pauseIfOverIdle;
|
|
3892
3893
|
private cancelRelease;
|
|
3893
3894
|
close(): void;
|
|
3894
3895
|
}
|
package/dist/index.js
CHANGED
|
@@ -6762,7 +6762,7 @@ var Freestyle = class {
|
|
|
6762
6762
|
// ../sandbox/package.json
|
|
6763
6763
|
var package_default = {
|
|
6764
6764
|
name: "@decocms/sandbox",
|
|
6765
|
-
version: "1.93.
|
|
6765
|
+
version: "1.93.5",
|
|
6766
6766
|
private: true,
|
|
6767
6767
|
type: "module",
|
|
6768
6768
|
description: "Sandbox runtime for isolated Studio tool execution",
|
|
@@ -7290,7 +7290,15 @@ ${head}`).digest("hex").slice(0, 16)}`;
|
|
|
7290
7290
|
const sentinel = this.sentinelToken(snapshotSlug);
|
|
7291
7291
|
const payload = this.configPayload(opts) ?? {};
|
|
7292
7292
|
try {
|
|
7293
|
-
await
|
|
7293
|
+
await retry(
|
|
7294
|
+
() => postConfig(url, sentinel, payload, { rotateToken: token }),
|
|
7295
|
+
{
|
|
7296
|
+
maxAttempts: 8,
|
|
7297
|
+
minTimeout: 250,
|
|
7298
|
+
maxTimeout: 4e3,
|
|
7299
|
+
isRetriable: (err) => err instanceof ConfigRequestError && err.status === 502
|
|
7300
|
+
}
|
|
7301
|
+
);
|
|
7294
7302
|
console.log(`[${LOG_LABEL2}] reclaimed ${url} after a reboot`);
|
|
7295
7303
|
return;
|
|
7296
7304
|
} catch (err) {
|
|
@@ -7588,40 +7596,20 @@ ${head}`).digest("hex").slice(0, 16)}`;
|
|
|
7588
7596
|
if (this.sweeping) return [];
|
|
7589
7597
|
this.sweeping = true;
|
|
7590
7598
|
try {
|
|
7591
|
-
const
|
|
7592
|
-
for (let offset = 0; ;
|
|
7599
|
+
const paused = [];
|
|
7600
|
+
for (let offset = 0; ; ) {
|
|
7593
7601
|
const { vms } = await this.freestyle.vms.list({
|
|
7594
7602
|
state: "running",
|
|
7595
7603
|
limit: IDLE_SWEEP_PAGE,
|
|
7596
7604
|
offset
|
|
7597
7605
|
});
|
|
7598
|
-
|
|
7606
|
+
const results = await Promise.all(
|
|
7607
|
+
vms.map((data) => this.pauseIfOverIdle(data))
|
|
7608
|
+
);
|
|
7609
|
+
paused.push(...results);
|
|
7599
7610
|
if (vms.length < IDLE_SWEEP_PAGE) break;
|
|
7611
|
+
offset += vms.length - results.filter((h) => h !== null).length;
|
|
7600
7612
|
}
|
|
7601
|
-
const paused = await Promise.all(
|
|
7602
|
-
running.map(async (data) => {
|
|
7603
|
-
const handle = data.slug;
|
|
7604
|
-
if (!handle || !data.metadata[TOKEN_KEY]) return null;
|
|
7605
|
-
if (Date.now() - Date.parse(data.createdAt) < this.idlePauseMs) {
|
|
7606
|
-
return null;
|
|
7607
|
-
}
|
|
7608
|
-
const idleMs = await daemonIdleMs(this.daemonUrl(handle));
|
|
7609
|
-
if (idleMs === null || idleMs < this.idlePauseMs) return null;
|
|
7610
|
-
try {
|
|
7611
|
-
await this.freestyle.vms.ref(data.id).pause();
|
|
7612
|
-
} catch (err) {
|
|
7613
|
-
console.warn(
|
|
7614
|
-
`[${LOG_LABEL2}] pause ${handle} failed: ${errMsg2(err)}`
|
|
7615
|
-
);
|
|
7616
|
-
return null;
|
|
7617
|
-
}
|
|
7618
|
-
this.cancelRelease(handle);
|
|
7619
|
-
console.log(
|
|
7620
|
-
`[${LOG_LABEL2}] paused ${handle}, daemon idle ${Math.round(idleMs / 6e4)}m`
|
|
7621
|
-
);
|
|
7622
|
-
return handle;
|
|
7623
|
-
})
|
|
7624
|
-
);
|
|
7625
7613
|
return paused.filter((h) => h !== null);
|
|
7626
7614
|
} catch (err) {
|
|
7627
7615
|
console.warn(`[${LOG_LABEL2}] idle sweep failed: ${errMsg2(err)}`);
|
|
@@ -7630,6 +7618,26 @@ ${head}`).digest("hex").slice(0, 16)}`;
|
|
|
7630
7618
|
this.sweeping = false;
|
|
7631
7619
|
}
|
|
7632
7620
|
}
|
|
7621
|
+
async pauseIfOverIdle(data) {
|
|
7622
|
+
const handle = data.slug;
|
|
7623
|
+
if (!handle || !data.metadata[TOKEN_KEY]) return null;
|
|
7624
|
+
if (Date.now() - Date.parse(data.createdAt) < this.idlePauseMs) {
|
|
7625
|
+
return null;
|
|
7626
|
+
}
|
|
7627
|
+
const idleMs = await daemonIdleMs(this.daemonUrl(handle));
|
|
7628
|
+
if (idleMs === null || idleMs < this.idlePauseMs) return null;
|
|
7629
|
+
try {
|
|
7630
|
+
await this.freestyle.vms.ref(data.id).pause();
|
|
7631
|
+
} catch (err) {
|
|
7632
|
+
console.warn(`[${LOG_LABEL2}] pause ${handle} failed: ${errMsg2(err)}`);
|
|
7633
|
+
return null;
|
|
7634
|
+
}
|
|
7635
|
+
this.cancelRelease(handle);
|
|
7636
|
+
console.log(
|
|
7637
|
+
`[${LOG_LABEL2}] paused ${handle}, daemon idle ${Math.round(idleMs / 6e4)}m`
|
|
7638
|
+
);
|
|
7639
|
+
return handle;
|
|
7640
|
+
}
|
|
7633
7641
|
cancelRelease(handle) {
|
|
7634
7642
|
const timer = this.releaseTimers.get(handle);
|
|
7635
7643
|
if (timer) clearTimeout(timer);
|