@tscircuit/cli 0.1.1092 → 0.1.1093
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/cli/main.js +62 -1
- package/dist/lib/index.js +1 -1
- package/package.json +1 -1
package/dist/cli/main.js
CHANGED
|
@@ -71664,7 +71664,7 @@ var registerStaticAssetLoaders = () => {
|
|
|
71664
71664
|
// cli/main.ts
|
|
71665
71665
|
var import_perfect_cli = __toESM2(require_dist2(), 1);
|
|
71666
71666
|
// package.json
|
|
71667
|
-
var version = "0.1.
|
|
71667
|
+
var version = "0.1.1092";
|
|
71668
71668
|
var package_default = {
|
|
71669
71669
|
name: "@tscircuit/cli",
|
|
71670
71670
|
version,
|
|
@@ -81960,6 +81960,7 @@ class ThreadWorkerPool {
|
|
|
81960
81960
|
initialized = false;
|
|
81961
81961
|
stopped = false;
|
|
81962
81962
|
stopReason = null;
|
|
81963
|
+
heartbeatIntervalId = null;
|
|
81963
81964
|
constructor(options) {
|
|
81964
81965
|
this.options = options;
|
|
81965
81966
|
this.concurrency = options.concurrency;
|
|
@@ -81970,13 +81971,68 @@ class ThreadWorkerPool {
|
|
|
81970
81971
|
for (let i = 0;i < this.concurrency; i++) {
|
|
81971
81972
|
this.workers.push(this.createThreadWorker());
|
|
81972
81973
|
}
|
|
81974
|
+
this.startHeartbeat();
|
|
81973
81975
|
this.initialized = true;
|
|
81974
81976
|
}
|
|
81977
|
+
describeJob(job) {
|
|
81978
|
+
if (this.options.describeJob) {
|
|
81979
|
+
return this.options.describeJob(job);
|
|
81980
|
+
}
|
|
81981
|
+
if (typeof job === "object" && job !== null) {
|
|
81982
|
+
const jobCandidate = job;
|
|
81983
|
+
if (typeof jobCandidate.filePath === "string") {
|
|
81984
|
+
return jobCandidate.filePath;
|
|
81985
|
+
}
|
|
81986
|
+
if (typeof jobCandidate.id === "string") {
|
|
81987
|
+
return jobCandidate.id;
|
|
81988
|
+
}
|
|
81989
|
+
if (typeof jobCandidate.outputPath === "string") {
|
|
81990
|
+
return jobCandidate.outputPath;
|
|
81991
|
+
}
|
|
81992
|
+
}
|
|
81993
|
+
return "unknown-job";
|
|
81994
|
+
}
|
|
81995
|
+
startHeartbeat() {
|
|
81996
|
+
if (!this.options.onLog || this.heartbeatIntervalId) {
|
|
81997
|
+
return;
|
|
81998
|
+
}
|
|
81999
|
+
const heartbeatIntervalMs = this.options.heartbeatIntervalMs ?? 5000;
|
|
82000
|
+
if (heartbeatIntervalMs <= 0) {
|
|
82001
|
+
return;
|
|
82002
|
+
}
|
|
82003
|
+
this.heartbeatIntervalId = setInterval(() => {
|
|
82004
|
+
const busyWorkers = this.workers.filter((worker) => worker.busy).length;
|
|
82005
|
+
const totalWorkers = this.workers.length;
|
|
82006
|
+
const idleWorkers = totalWorkers - busyWorkers;
|
|
82007
|
+
const queuedJobs = this.jobQueue.length;
|
|
82008
|
+
const now = Date.now();
|
|
82009
|
+
const workerDetails = this.workers.map((worker, index) => {
|
|
82010
|
+
if (!worker.busy || !worker.currentJob || !worker.currentJobStartedAt) {
|
|
82011
|
+
return `w${index}:idle`;
|
|
82012
|
+
}
|
|
82013
|
+
const runningForMs = now - worker.currentJobStartedAt;
|
|
82014
|
+
const jobDescription = this.describeJob(worker.currentJob.job);
|
|
82015
|
+
return `w${index}:busy task=${jobDescription} running_ms=${runningForMs}`;
|
|
82016
|
+
});
|
|
82017
|
+
this.options.onLog?.([
|
|
82018
|
+
`[worker-pool] heartbeat: workers busy=${busyWorkers}/${totalWorkers}, idle=${idleWorkers}, queued_jobs=${queuedJobs} | ${workerDetails.join(" | ")}`
|
|
82019
|
+
]);
|
|
82020
|
+
}, heartbeatIntervalMs);
|
|
82021
|
+
this.heartbeatIntervalId.unref?.();
|
|
82022
|
+
}
|
|
82023
|
+
stopHeartbeat() {
|
|
82024
|
+
if (!this.heartbeatIntervalId) {
|
|
82025
|
+
return;
|
|
82026
|
+
}
|
|
82027
|
+
clearInterval(this.heartbeatIntervalId);
|
|
82028
|
+
this.heartbeatIntervalId = null;
|
|
82029
|
+
}
|
|
81975
82030
|
createThreadWorker() {
|
|
81976
82031
|
const threadWorker = {
|
|
81977
82032
|
worker: new Worker(this.options.workerEntrypointPath),
|
|
81978
82033
|
busy: false,
|
|
81979
82034
|
currentJob: null,
|
|
82035
|
+
currentJobStartedAt: null,
|
|
81980
82036
|
timeoutId: null
|
|
81981
82037
|
};
|
|
81982
82038
|
this.attachWorkerHandlers(threadWorker);
|
|
@@ -82016,6 +82072,7 @@ class ThreadWorkerPool {
|
|
|
82016
82072
|
threadWorker.worker = new Worker(this.options.workerEntrypointPath);
|
|
82017
82073
|
threadWorker.busy = false;
|
|
82018
82074
|
threadWorker.currentJob = null;
|
|
82075
|
+
threadWorker.currentJobStartedAt = null;
|
|
82019
82076
|
this.attachWorkerHandlers(threadWorker);
|
|
82020
82077
|
}
|
|
82021
82078
|
finishJob(threadWorker, action) {
|
|
@@ -82025,6 +82082,7 @@ class ThreadWorkerPool {
|
|
|
82025
82082
|
}
|
|
82026
82083
|
this.clearWorkerTimeout(threadWorker);
|
|
82027
82084
|
threadWorker.currentJob = null;
|
|
82085
|
+
threadWorker.currentJobStartedAt = null;
|
|
82028
82086
|
threadWorker.busy = false;
|
|
82029
82087
|
action(job);
|
|
82030
82088
|
this.processQueue();
|
|
@@ -82089,6 +82147,7 @@ class ThreadWorkerPool {
|
|
|
82089
82147
|
}
|
|
82090
82148
|
availableWorker.busy = true;
|
|
82091
82149
|
availableWorker.currentJob = queuedJob;
|
|
82150
|
+
availableWorker.currentJobStartedAt = Date.now();
|
|
82092
82151
|
this.startJobTimeout(availableWorker);
|
|
82093
82152
|
availableWorker.worker.postMessage(this.options.createMessage(queuedJob.job));
|
|
82094
82153
|
}
|
|
@@ -82106,6 +82165,7 @@ class ThreadWorkerPool {
|
|
|
82106
82165
|
if (this.stopped)
|
|
82107
82166
|
return;
|
|
82108
82167
|
this.stopped = true;
|
|
82168
|
+
this.stopHeartbeat();
|
|
82109
82169
|
this.stopReason = reason;
|
|
82110
82170
|
for (const queuedJob of this.jobQueue) {
|
|
82111
82171
|
queuedJob.reject(reason);
|
|
@@ -82113,6 +82173,7 @@ class ThreadWorkerPool {
|
|
|
82113
82173
|
this.jobQueue = [];
|
|
82114
82174
|
}
|
|
82115
82175
|
async terminate() {
|
|
82176
|
+
this.stopHeartbeat();
|
|
82116
82177
|
await Promise.all(this.workers.map((worker) => {
|
|
82117
82178
|
this.clearWorkerTimeout(worker);
|
|
82118
82179
|
return worker.worker.terminate();
|
package/dist/lib/index.js
CHANGED
|
@@ -60435,7 +60435,7 @@ var getNodeHandler = (winterSpec, { port, middleware = [] }) => {
|
|
|
60435
60435
|
}));
|
|
60436
60436
|
};
|
|
60437
60437
|
// package.json
|
|
60438
|
-
var version = "0.1.
|
|
60438
|
+
var version = "0.1.1092";
|
|
60439
60439
|
var package_default = {
|
|
60440
60440
|
name: "@tscircuit/cli",
|
|
60441
60441
|
version,
|