@matterbridge/thread 3.9.2-dev-20260625-a938372 → 3.9.2-dev-20260625-9f0a35e
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/threadsManager.js +31 -17
- package/package.json +3 -3
package/dist/threadsManager.js
CHANGED
|
@@ -116,38 +116,52 @@ export class ThreadsManager {
|
|
|
116
116
|
threadInfo.worker = this.createESMWorker(threadInfo.name, path, { ...workerData, debug: this.debug, verbose: this.verbose, logLevel: this.log.logLevel }, argv, env, execArgv, pipedOutput);
|
|
117
117
|
const worker = threadInfo.worker;
|
|
118
118
|
worker.once('online', () => {
|
|
119
|
-
|
|
120
|
-
threadInfo.
|
|
121
|
-
threadInfo.lastSeen = Date.now();
|
|
122
|
-
this.log.debug(`Thread ${threadInfo.name} is online started at ${new Date(threadInfo.lastStarted).toISOString()} with thread id ${worker.threadId}`);
|
|
119
|
+
const now = Date.now();
|
|
120
|
+
this.log.debug(`Thread ${threadInfo.name} is online at ${new Date(now).toISOString()}`);
|
|
123
121
|
});
|
|
124
122
|
worker.once('exit', () => {
|
|
125
|
-
const
|
|
126
|
-
threadInfo.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
if (threadInfo.worker === worker) {
|
|
125
|
+
threadInfo.lastSeen = now;
|
|
126
|
+
threadInfo.lastStopped = now;
|
|
127
|
+
threadInfo.lastDuration = Math.max(0, now - (threadInfo.lastStarted ?? now));
|
|
128
|
+
threadInfo.worker = undefined;
|
|
129
|
+
}
|
|
130
|
+
this.log.debug(`Thread ${threadInfo.name} has exited at ${new Date(now).toISOString()}`);
|
|
131
131
|
});
|
|
132
132
|
worker.on('message', (message) => {
|
|
133
|
-
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
threadInfo.lastSeen = now;
|
|
134
135
|
if (this.verbose)
|
|
135
|
-
this.log.debug(`Thread ${threadInfo.name} sent a message at ${new Date().toISOString()}: ${debugStringify(message)}`);
|
|
136
|
+
this.log.debug(`Thread ${threadInfo.name} sent a message at ${new Date(now).toISOString()}: ${debugStringify(message)}`);
|
|
136
137
|
if (message.type === 'log') {
|
|
137
138
|
AnsiLogger.create({ logName: threadInfo.name, logNameColor: MAGENTA, logTimestampFormat: 4, logLevel: this.log.logLevel }).log(message.logLevel, message.message);
|
|
138
139
|
}
|
|
140
|
+
else if (message.type === 'init') {
|
|
141
|
+
threadInfo.lastStarted = now;
|
|
142
|
+
threadInfo.runCount = (threadInfo.runCount ?? 0) + 1;
|
|
143
|
+
this.log.debug(`Thread ${threadInfo.name} is online started at ${new Date(now).toISOString()} with thread id ${worker.threadId}`);
|
|
144
|
+
}
|
|
145
|
+
else if (message.type === 'exit') {
|
|
146
|
+
threadInfo.lastStopped = now;
|
|
147
|
+
threadInfo.lastDuration = Math.max(0, now - (threadInfo.lastStarted ?? now));
|
|
148
|
+
threadInfo.worker = undefined;
|
|
149
|
+
this.log.debug(`Thread ${threadInfo.name} has exited at ${new Date(now).toISOString()} with thread id ${worker.threadId} after running for ${threadInfo.lastDuration} ms`);
|
|
150
|
+
}
|
|
139
151
|
});
|
|
140
152
|
worker.on('messageerror', () => {
|
|
153
|
+
const now = Date.now();
|
|
141
154
|
threadInfo.errorCount = (threadInfo.errorCount ?? 0) + 1;
|
|
142
|
-
this.log.error(`Thread ${threadInfo.name} encountered a message error at ${new Date().toISOString()}`);
|
|
155
|
+
this.log.error(`Thread ${threadInfo.name} encountered a message error at ${new Date(now).toISOString()}`);
|
|
143
156
|
});
|
|
144
157
|
worker.once('error', (error) => {
|
|
158
|
+
const now = Date.now();
|
|
145
159
|
threadInfo.errorCount = (threadInfo.errorCount ?? 0) + 1;
|
|
146
|
-
|
|
147
|
-
threadInfo.
|
|
148
|
-
threadInfo.lastDuration = Math.max(0, stoppedAt - (threadInfo.lastStarted ?? stoppedAt));
|
|
160
|
+
threadInfo.lastStopped = now;
|
|
161
|
+
threadInfo.lastDuration = Math.max(0, now - (threadInfo.lastStarted ?? now));
|
|
149
162
|
threadInfo.worker = undefined;
|
|
150
|
-
|
|
163
|
+
threadInfo.lastSeen = now;
|
|
164
|
+
this.log.error(`Thread ${threadInfo.name} encountered an error at ${new Date(now).toISOString()} after running for ${threadInfo.lastDuration} ms: ${getErrorMessage(error)}`);
|
|
151
165
|
});
|
|
152
166
|
this.log.debug(`Started thread ${threadInfo.name} from path ${path} type ${threadInfo.type} with thread id ${worker.threadId}`);
|
|
153
167
|
return threadInfo.worker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matterbridge/thread",
|
|
3
|
-
"version": "3.9.2-dev-20260625-
|
|
3
|
+
"version": "3.9.2-dev-20260625-9f0a35e",
|
|
4
4
|
"description": "Matterbridge thread library",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"homepage": "https://matterbridge.io/",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"CHANGELOG.md"
|
|
70
70
|
],
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@matterbridge/types": "3.9.2-dev-20260625-
|
|
73
|
-
"@matterbridge/utils": "3.9.2-dev-20260625-
|
|
72
|
+
"@matterbridge/types": "3.9.2-dev-20260625-9f0a35e",
|
|
73
|
+
"@matterbridge/utils": "3.9.2-dev-20260625-9f0a35e",
|
|
74
74
|
"@zip.js/zip.js": "2.8.26",
|
|
75
75
|
"node-ansi-logger": "3.3.0"
|
|
76
76
|
}
|