@decocms/sandbox-controller 0.12.4 → 0.13.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.d.ts +1 -0
- package/dist/index.js +38 -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
|
@@ -1469,6 +1469,7 @@ var RepositorySchema = z.object({
|
|
|
1469
1469
|
sandboxImage: SandboxImageSchema.describe(
|
|
1470
1470
|
"Sandbox image this repository's sandboxes boot from."
|
|
1471
1471
|
),
|
|
1472
|
+
monitorDeploys: z.boolean().describe("Its default-branch pushes show on the Monitor's Deploys tab."),
|
|
1472
1473
|
createdAt: z.string(),
|
|
1473
1474
|
updatedAt: z.string()
|
|
1474
1475
|
});
|
|
@@ -6762,7 +6763,7 @@ var Freestyle = class {
|
|
|
6762
6763
|
// ../sandbox/package.json
|
|
6763
6764
|
var package_default = {
|
|
6764
6765
|
name: "@decocms/sandbox",
|
|
6765
|
-
version: "1.93.
|
|
6766
|
+
version: "1.93.5",
|
|
6766
6767
|
private: true,
|
|
6767
6768
|
type: "module",
|
|
6768
6769
|
description: "Sandbox runtime for isolated Studio tool execution",
|
|
@@ -7290,7 +7291,15 @@ ${head}`).digest("hex").slice(0, 16)}`;
|
|
|
7290
7291
|
const sentinel = this.sentinelToken(snapshotSlug);
|
|
7291
7292
|
const payload = this.configPayload(opts) ?? {};
|
|
7292
7293
|
try {
|
|
7293
|
-
await
|
|
7294
|
+
await retry(
|
|
7295
|
+
() => postConfig(url, sentinel, payload, { rotateToken: token }),
|
|
7296
|
+
{
|
|
7297
|
+
maxAttempts: 8,
|
|
7298
|
+
minTimeout: 250,
|
|
7299
|
+
maxTimeout: 4e3,
|
|
7300
|
+
isRetriable: (err) => err instanceof ConfigRequestError && err.status === 502
|
|
7301
|
+
}
|
|
7302
|
+
);
|
|
7294
7303
|
console.log(`[${LOG_LABEL2}] reclaimed ${url} after a reboot`);
|
|
7295
7304
|
return;
|
|
7296
7305
|
} catch (err) {
|
|
@@ -7588,40 +7597,20 @@ ${head}`).digest("hex").slice(0, 16)}`;
|
|
|
7588
7597
|
if (this.sweeping) return [];
|
|
7589
7598
|
this.sweeping = true;
|
|
7590
7599
|
try {
|
|
7591
|
-
const
|
|
7592
|
-
for (let offset = 0; ;
|
|
7600
|
+
const paused = [];
|
|
7601
|
+
for (let offset = 0; ; ) {
|
|
7593
7602
|
const { vms } = await this.freestyle.vms.list({
|
|
7594
7603
|
state: "running",
|
|
7595
7604
|
limit: IDLE_SWEEP_PAGE,
|
|
7596
7605
|
offset
|
|
7597
7606
|
});
|
|
7598
|
-
|
|
7607
|
+
const results = await Promise.all(
|
|
7608
|
+
vms.map((data) => this.pauseIfOverIdle(data))
|
|
7609
|
+
);
|
|
7610
|
+
paused.push(...results);
|
|
7599
7611
|
if (vms.length < IDLE_SWEEP_PAGE) break;
|
|
7612
|
+
offset += vms.length - results.filter((h) => h !== null).length;
|
|
7600
7613
|
}
|
|
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
7614
|
return paused.filter((h) => h !== null);
|
|
7626
7615
|
} catch (err) {
|
|
7627
7616
|
console.warn(`[${LOG_LABEL2}] idle sweep failed: ${errMsg2(err)}`);
|
|
@@ -7630,6 +7619,26 @@ ${head}`).digest("hex").slice(0, 16)}`;
|
|
|
7630
7619
|
this.sweeping = false;
|
|
7631
7620
|
}
|
|
7632
7621
|
}
|
|
7622
|
+
async pauseIfOverIdle(data) {
|
|
7623
|
+
const handle = data.slug;
|
|
7624
|
+
if (!handle || !data.metadata[TOKEN_KEY]) return null;
|
|
7625
|
+
if (Date.now() - Date.parse(data.createdAt) < this.idlePauseMs) {
|
|
7626
|
+
return null;
|
|
7627
|
+
}
|
|
7628
|
+
const idleMs = await daemonIdleMs(this.daemonUrl(handle));
|
|
7629
|
+
if (idleMs === null || idleMs < this.idlePauseMs) return null;
|
|
7630
|
+
try {
|
|
7631
|
+
await this.freestyle.vms.ref(data.id).pause();
|
|
7632
|
+
} catch (err) {
|
|
7633
|
+
console.warn(`[${LOG_LABEL2}] pause ${handle} failed: ${errMsg2(err)}`);
|
|
7634
|
+
return null;
|
|
7635
|
+
}
|
|
7636
|
+
this.cancelRelease(handle);
|
|
7637
|
+
console.log(
|
|
7638
|
+
`[${LOG_LABEL2}] paused ${handle}, daemon idle ${Math.round(idleMs / 6e4)}m`
|
|
7639
|
+
);
|
|
7640
|
+
return handle;
|
|
7641
|
+
}
|
|
7633
7642
|
cancelRelease(handle) {
|
|
7634
7643
|
const timer = this.releaseTimers.get(handle);
|
|
7635
7644
|
if (timer) clearTimeout(timer);
|