@open-mercato/cli 0.6.1-develop.3291.1.6fad645fd0 → 0.6.1
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/.turbo/turbo-build.log +1 -1
- package/dist/lib/auto-spawn-scheduler.js +37 -0
- package/dist/lib/auto-spawn-scheduler.js.map +7 -0
- package/dist/lib/scheduler-supervisor.js +216 -0
- package/dist/lib/scheduler-supervisor.js.map +7 -0
- package/dist/lib/testing/integration.js +9 -1
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/mercato.js +54 -8
- package/dist/mercato.js.map +2 -2
- package/package.json +6 -7
- package/src/__tests__/mercato.test.ts +88 -0
- package/src/lib/__tests__/auto-spawn-scheduler.test.ts +63 -0
- package/src/lib/__tests__/scheduler-supervisor.test.ts +199 -0
- package/src/lib/auto-spawn-scheduler.ts +39 -0
- package/src/lib/scheduler-supervisor.ts +286 -0
- package/src/lib/testing/__tests__/integration.test.ts +12 -0
- package/src/lib/testing/integration.ts +9 -1
- package/src/mercato.ts +56 -8
package/dist/mercato.js
CHANGED
|
@@ -10,6 +10,12 @@ import {
|
|
|
10
10
|
resolveLazyRestart
|
|
11
11
|
} from "./lib/auto-spawn-workers.js";
|
|
12
12
|
import { startLazyWorkerSupervisor } from "./lib/queue-worker-supervisor.js";
|
|
13
|
+
import {
|
|
14
|
+
resolveAutoSpawnSchedulerMode,
|
|
15
|
+
resolveLazySchedulerPollMs,
|
|
16
|
+
resolveLazySchedulerRestart
|
|
17
|
+
} from "./lib/auto-spawn-scheduler.js";
|
|
18
|
+
import { startLazySchedulerSupervisor } from "./lib/scheduler-supervisor.js";
|
|
13
19
|
import { parseModuleInstallArgs } from "./lib/module-install-args.js";
|
|
14
20
|
import { resolveNextBuildIdCandidate } from "./lib/next-build-id.js";
|
|
15
21
|
import { acquireServerStartLock } from "./lib/server-start-lock.js";
|
|
@@ -1393,6 +1399,7 @@ async function run(argv = process.argv) {
|
|
|
1393
1399
|
let stopping = false;
|
|
1394
1400
|
let envChangePromiseResolve = null;
|
|
1395
1401
|
let activeLazySupervisor = null;
|
|
1402
|
+
let activeLazySchedulerSupervisor = null;
|
|
1396
1403
|
const envReloader = createDevEnvReloader(appDir, process.env, initialProcessEnvironmentEntries);
|
|
1397
1404
|
function cleanup() {
|
|
1398
1405
|
console.log("[server] Shutting down...");
|
|
@@ -1404,6 +1411,9 @@ async function run(argv = process.argv) {
|
|
|
1404
1411
|
if (activeLazySupervisor) {
|
|
1405
1412
|
void activeLazySupervisor.close().catch(() => void 0);
|
|
1406
1413
|
}
|
|
1414
|
+
if (activeLazySchedulerSupervisor) {
|
|
1415
|
+
void activeLazySchedulerSupervisor.close().catch(() => void 0);
|
|
1416
|
+
}
|
|
1407
1417
|
}
|
|
1408
1418
|
async function cleanupAndWait() {
|
|
1409
1419
|
cleanup();
|
|
@@ -1422,6 +1432,13 @@ async function run(argv = process.argv) {
|
|
|
1422
1432
|
}
|
|
1423
1433
|
activeLazySupervisor = null;
|
|
1424
1434
|
}
|
|
1435
|
+
if (activeLazySchedulerSupervisor) {
|
|
1436
|
+
try {
|
|
1437
|
+
await activeLazySchedulerSupervisor.close();
|
|
1438
|
+
} catch {
|
|
1439
|
+
}
|
|
1440
|
+
activeLazySchedulerSupervisor = null;
|
|
1441
|
+
}
|
|
1425
1442
|
const lockFile = path.join(appDir, ".mercato", "next", "dev", "lock");
|
|
1426
1443
|
try {
|
|
1427
1444
|
fs.unlinkSync(lockFile);
|
|
@@ -1496,7 +1513,7 @@ async function run(argv = process.argv) {
|
|
|
1496
1513
|
envReloader.reload();
|
|
1497
1514
|
const runtimeEnv = buildServerProcessEnvironment(process.env);
|
|
1498
1515
|
const autoSpawnWorkersMode = resolveAutoSpawnWorkersMode(process.env);
|
|
1499
|
-
const
|
|
1516
|
+
const autoSpawnSchedulerMode = resolveAutoSpawnSchedulerMode(process.env);
|
|
1500
1517
|
const queueStrategy = process.env.QUEUE_STRATEGY || "local";
|
|
1501
1518
|
const schedulerCommand = lookupModuleCommand(getCliModules(), "scheduler", "start");
|
|
1502
1519
|
const managedExitPromises = [
|
|
@@ -1519,7 +1536,7 @@ async function run(argv = process.argv) {
|
|
|
1519
1536
|
restartOnUnexpectedExit: resolveLazyRestart(process.env)
|
|
1520
1537
|
});
|
|
1521
1538
|
} else {
|
|
1522
|
-
console.log("[server]
|
|
1539
|
+
console.log("[server] Eager worker auto-spawn enabled - starting workers for all queues...");
|
|
1523
1540
|
const workerProcess = spawn("node", [mercatoBin, "queue", "worker", "--all"], {
|
|
1524
1541
|
stdio: "inherit",
|
|
1525
1542
|
env: runtimeEnv,
|
|
@@ -1529,11 +1546,20 @@ async function run(argv = process.argv) {
|
|
|
1529
1546
|
managedExitPromises.push(waitForManagedProcessExit(workerProcess, formatQueueWorkerLabel(discoveredWorkerQueues)));
|
|
1530
1547
|
}
|
|
1531
1548
|
}
|
|
1532
|
-
if (
|
|
1549
|
+
if (autoSpawnSchedulerMode !== "off" && queueStrategy === "local") {
|
|
1533
1550
|
if (schedulerCommand.status !== "ok") {
|
|
1534
1551
|
console.log(`[server] Skipping scheduler auto-start \u2014 ${describeMissingModuleCommand(schedulerCommand)}`);
|
|
1552
|
+
} else if (autoSpawnSchedulerMode === "lazy") {
|
|
1553
|
+
console.log("[server] Lazy scheduler auto-spawn enabled - scheduler will start when an enabled schedule exists.");
|
|
1554
|
+
activeLazySchedulerSupervisor = startLazySchedulerSupervisor({
|
|
1555
|
+
mercatoBin,
|
|
1556
|
+
appDir,
|
|
1557
|
+
runtimeEnv,
|
|
1558
|
+
pollMs: resolveLazySchedulerPollMs(process.env),
|
|
1559
|
+
restartOnUnexpectedExit: resolveLazySchedulerRestart(process.env)
|
|
1560
|
+
});
|
|
1535
1561
|
} else {
|
|
1536
|
-
console.log("[server]
|
|
1562
|
+
console.log("[server] Eager scheduler auto-spawn enabled - starting scheduler polling engine...");
|
|
1537
1563
|
const schedulerProcess = spawn("node", [mercatoBin, "scheduler", "start"], {
|
|
1538
1564
|
stdio: "inherit",
|
|
1539
1565
|
env: runtimeEnv,
|
|
@@ -1570,7 +1596,7 @@ async function run(argv = process.argv) {
|
|
|
1570
1596
|
const nodeModulesBases = Array.from(/* @__PURE__ */ new Set([env.rootDir, appDir]));
|
|
1571
1597
|
const processes = [];
|
|
1572
1598
|
const autoSpawnWorkersMode = resolveAutoSpawnWorkersMode(process.env);
|
|
1573
|
-
const
|
|
1599
|
+
const autoSpawnSchedulerMode = resolveAutoSpawnSchedulerMode(process.env);
|
|
1574
1600
|
const queueStrategy = process.env.QUEUE_STRATEGY || "local";
|
|
1575
1601
|
const runtimeEnv = buildServerProcessEnvironment(process.env);
|
|
1576
1602
|
const schedulerCommand = lookupModuleCommand(getCliModules(), "scheduler", "start");
|
|
@@ -1578,6 +1604,7 @@ async function run(argv = process.argv) {
|
|
|
1578
1604
|
port: runtimeEnv.PORT ?? process.env.PORT ?? null
|
|
1579
1605
|
});
|
|
1580
1606
|
let activeLazySupervisor = null;
|
|
1607
|
+
let activeLazySchedulerSupervisor = null;
|
|
1581
1608
|
let stopping = false;
|
|
1582
1609
|
function cleanup() {
|
|
1583
1610
|
console.log("[server] Shutting down...");
|
|
@@ -1589,6 +1616,9 @@ async function run(argv = process.argv) {
|
|
|
1589
1616
|
if (activeLazySupervisor) {
|
|
1590
1617
|
void activeLazySupervisor.close().catch(() => void 0);
|
|
1591
1618
|
}
|
|
1619
|
+
if (activeLazySchedulerSupervisor) {
|
|
1620
|
+
void activeLazySchedulerSupervisor.close().catch(() => void 0);
|
|
1621
|
+
}
|
|
1592
1622
|
}
|
|
1593
1623
|
async function cleanupAndWait() {
|
|
1594
1624
|
cleanup();
|
|
@@ -1607,6 +1637,13 @@ async function run(argv = process.argv) {
|
|
|
1607
1637
|
}
|
|
1608
1638
|
activeLazySupervisor = null;
|
|
1609
1639
|
}
|
|
1640
|
+
if (activeLazySchedulerSupervisor) {
|
|
1641
|
+
try {
|
|
1642
|
+
await activeLazySchedulerSupervisor.close();
|
|
1643
|
+
} catch {
|
|
1644
|
+
}
|
|
1645
|
+
activeLazySchedulerSupervisor = null;
|
|
1646
|
+
}
|
|
1610
1647
|
}
|
|
1611
1648
|
process.on("SIGTERM", () => {
|
|
1612
1649
|
stopping = true;
|
|
@@ -1646,7 +1683,7 @@ async function run(argv = process.argv) {
|
|
|
1646
1683
|
restartOnUnexpectedExit: resolveLazyRestart(process.env)
|
|
1647
1684
|
});
|
|
1648
1685
|
} else {
|
|
1649
|
-
console.log("[server]
|
|
1686
|
+
console.log("[server] Eager worker auto-spawn enabled - starting workers for all queues...");
|
|
1650
1687
|
const workerProcess = spawn("node", [mercatoBin, "queue", "worker", "--all"], {
|
|
1651
1688
|
stdio: "inherit",
|
|
1652
1689
|
env: runtimeEnv,
|
|
@@ -1656,11 +1693,20 @@ async function run(argv = process.argv) {
|
|
|
1656
1693
|
managedExitPromises.push(waitForManagedProcessExit(workerProcess, formatQueueWorkerLabel(discoveredWorkerQueues)));
|
|
1657
1694
|
}
|
|
1658
1695
|
}
|
|
1659
|
-
if (
|
|
1696
|
+
if (autoSpawnSchedulerMode !== "off" && queueStrategy === "local") {
|
|
1660
1697
|
if (schedulerCommand.status !== "ok") {
|
|
1661
1698
|
console.log(`[server] Skipping scheduler auto-start \u2014 ${describeMissingModuleCommand(schedulerCommand)}`);
|
|
1699
|
+
} else if (autoSpawnSchedulerMode === "lazy") {
|
|
1700
|
+
console.log("[server] Lazy scheduler auto-spawn enabled - scheduler will start when an enabled schedule exists.");
|
|
1701
|
+
activeLazySchedulerSupervisor = startLazySchedulerSupervisor({
|
|
1702
|
+
mercatoBin,
|
|
1703
|
+
appDir,
|
|
1704
|
+
runtimeEnv,
|
|
1705
|
+
pollMs: resolveLazySchedulerPollMs(process.env),
|
|
1706
|
+
restartOnUnexpectedExit: resolveLazySchedulerRestart(process.env)
|
|
1707
|
+
});
|
|
1662
1708
|
} else {
|
|
1663
|
-
console.log("[server]
|
|
1709
|
+
console.log("[server] Eager scheduler auto-spawn enabled - starting scheduler polling engine...");
|
|
1664
1710
|
const schedulerProcess = spawn("node", [mercatoBin, "scheduler", "start"], {
|
|
1665
1711
|
stdio: "inherit",
|
|
1666
1712
|
env: runtimeEnv,
|