@sentio/runtime 3.4.2 → 3.4.3-rc.2
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/lib/chunk-EXIISBRV.js +26084 -0
- package/lib/{chunk-M7AXVHAR.js.map → chunk-EXIISBRV.js.map} +1 -1
- package/lib/chunk-I45UXGDM.js +1697 -0
- package/lib/{chunk-TW627LH5.js.map → chunk-I45UXGDM.js.map} +1 -1
- package/lib/chunk-KVSDPGUI.js +50 -0
- package/lib/chunk-L2A6JPIQ.js +21 -0
- package/lib/{chunk-CJDESLYQ.js.map → chunk-L2A6JPIQ.js.map} +1 -1
- package/lib/chunk-SS7MVRE2.js +60369 -0
- package/lib/{chunk-ASPTWJQG.js.map → chunk-SS7MVRE2.js.map} +1 -1
- package/lib/getMachineId-bsd-QYFPRONP.js +41 -0
- package/lib/{getMachineId-bsd-CDSZ2S36.js.map → getMachineId-bsd-QYFPRONP.js.map} +1 -1
- package/lib/getMachineId-darwin-XC67FIUW.js +41 -0
- package/lib/{getMachineId-darwin-LM5BSWCG.js.map → getMachineId-darwin-XC67FIUW.js.map} +1 -1
- package/lib/getMachineId-linux-4G7ZY7LQ.js +33 -0
- package/lib/{getMachineId-linux-UA53ZQFA.js.map → getMachineId-linux-4G7ZY7LQ.js.map} +1 -1
- package/lib/getMachineId-unsupported-5IH5IW7P.js +24 -0
- package/lib/{getMachineId-unsupported-LDR77GGJ.js.map → getMachineId-unsupported-5IH5IW7P.js.map} +1 -1
- package/lib/getMachineId-win-WSA3TUKL.js +43 -0
- package/lib/{getMachineId-win-XULW45X4.js.map → getMachineId-win-WSA3TUKL.js.map} +1 -1
- package/lib/index.js +139 -1
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +30699 -73
- package/lib/processor-runner.js.map +1 -1
- package/lib/test-processor.test.js.map +1 -1
- package/package.json +1 -1
- package/src/processor-runner.ts +76 -16
- package/lib/chunk-ASPTWJQG.js +0 -117
- package/lib/chunk-AUPVVLD3.js +0 -3
- package/lib/chunk-CJDESLYQ.js +0 -3
- package/lib/chunk-M7AXVHAR.js +0 -26
- package/lib/chunk-TW627LH5.js +0 -3
- package/lib/getMachineId-bsd-CDSZ2S36.js +0 -3
- package/lib/getMachineId-darwin-LM5BSWCG.js +0 -4
- package/lib/getMachineId-linux-UA53ZQFA.js +0 -3
- package/lib/getMachineId-unsupported-LDR77GGJ.js +0 -3
- package/lib/getMachineId-win-XULW45X4.js +0 -3
- /package/lib/{chunk-AUPVVLD3.js.map → chunk-KVSDPGUI.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\nimport { AccountConfig, InitResponse, ProcessConfigResponse, ProcessStreamResponse_Partitions } from '@sentio/protos'\n\nexport class TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n\n async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {\n return {\n partitions: request.handlerIds.reduce(\n (acc, id) => ({\n ...acc,\n [id]: {\n userValue: 'test'\n }\n }),\n {}\n )\n }\n }\n\n async init(config: InitResponse): Promise<void> {\n config.chainIds = ['1']\n }\n\n async configure(config: ProcessConfigResponse, forChainId?: string): Promise<void> {\n config.accountConfigs = [\n AccountConfig.fromPartial({\n address: '0x',\n chainId: '1'\n })\n ]\n }\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\nimport { AccountConfig, InitResponse, ProcessConfigResponse, ProcessStreamResponse_Partitions } from '@sentio/protos'\n\nexport class TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n\n async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {\n return {\n partitions: request.handlerIds.reduce(\n (acc, id) => ({\n ...acc,\n [id]: {\n userValue: 'test'\n }\n }),\n {}\n )\n }\n }\n\n async init(config: InitResponse): Promise<void> {\n config.chainIds = ['1']\n }\n\n async configure(config: ProcessConfigResponse, forChainId?: string): Promise<void> {\n config.accountConfigs = [\n AccountConfig.fromPartial({\n address: '0x',\n chainId: '1'\n })\n ]\n }\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;;;;;AAIO,IAAM,aAAN,cAAyB,OAAO;AAAA,EACrC,MAAM,eAAe,SAA8C;AACjE,UAAM,YAAY,cAAc,SAAS,sBAAsB,SAAS;AACxE,QAAI,WAAW;AACb,YAAM,UAAU,YAAY;AAAA,QAC1B,KAAK;AAAA,UACH,QAAQ;AAAA,UACR,IAAI;AAAA,QACN;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,cAAc,YAAY;AAAA,MAC/B,QAAQ;AAAA,QACN,eAAe;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,oBAAoB,iCAAyC;AAAA,EAE7D,MAAM,UAAU,SAAiE;AAC/E,WAAO;AAAA,MACL,YAAY,QAAQ,WAAW;AAAA,QAC7B,CAAC,KAAK,QAAQ;AAAA,UACZ,GAAG;AAAA,UACH,CAAC,EAAE,GAAG;AAAA,YACJ,WAAW;AAAA,UACb;AAAA,QACF;AAAA,QACA,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,KAAK,QAAqC;AAC9C,WAAO,WAAW,CAAC,GAAG;AAAA,EACxB;AAAA,EAEA,MAAM,UAAU,QAA+B,YAAoC;AACjF,WAAO,iBAAiB;AAAA,MACtB,cAAc,YAAY;AAAA,QACxB,SAAS;AAAA,QACT,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,cAAc,SAAS,UAAU,CAAC;AAClC,cAAc,SAAS,SAAS,IAAI,WAAW,CAAC;AAC/C,OAAO,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;","names":[]}
|
package/package.json
CHANGED
package/src/processor-runner.ts
CHANGED
|
@@ -35,6 +35,11 @@ const options: ProcessorRuntimeOptions = {
|
|
|
35
35
|
|
|
36
36
|
const logLevel = process.env['LOG_LEVEL']?.toLowerCase()
|
|
37
37
|
|
|
38
|
+
// Track parent shutdown so worker restarts do not happen during intentional exits.
|
|
39
|
+
let isParentShuttingDown = false
|
|
40
|
+
let areChildrenShuttingDown = false
|
|
41
|
+
let shutdownChildren = () => {}
|
|
42
|
+
|
|
38
43
|
setupLogger(options.logFormat === 'json', logLevel === 'debug' ? true : options.debug!)
|
|
39
44
|
console.debug('Starting with', options.target)
|
|
40
45
|
|
|
@@ -49,6 +54,14 @@ console.debug('Starting Server', options)
|
|
|
49
54
|
// Check if this is a child process spawned for multi-server mode
|
|
50
55
|
const isChildProcess = process.env['IS_CHILD'] === 'true'
|
|
51
56
|
|
|
57
|
+
function exitProcess(exitCode: number): never {
|
|
58
|
+
if (!isChildProcess) {
|
|
59
|
+
isParentShuttingDown = true
|
|
60
|
+
shutdownChildren()
|
|
61
|
+
}
|
|
62
|
+
process.exit(exitCode)
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
if (!isChildProcess) {
|
|
53
66
|
const sdkPackageJson = locatePackageJson('@sentio/sdk')
|
|
54
67
|
const runtimePackageJson = locatePackageJson('@sentio/runtime')
|
|
@@ -177,7 +190,20 @@ if (!isChildProcess) {
|
|
|
177
190
|
|
|
178
191
|
// Process event handlers
|
|
179
192
|
process
|
|
180
|
-
.
|
|
193
|
+
.once('SIGINT', function () {
|
|
194
|
+
if (isParentShuttingDown) {
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
isParentShuttingDown = true
|
|
198
|
+
shutdownChildren()
|
|
199
|
+
shutdownServers(0)
|
|
200
|
+
})
|
|
201
|
+
.once('SIGTERM', function () {
|
|
202
|
+
if (isParentShuttingDown) {
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
isParentShuttingDown = true
|
|
206
|
+
shutdownChildren()
|
|
181
207
|
shutdownServers(0)
|
|
182
208
|
})
|
|
183
209
|
.on('uncaughtException', (err) => {
|
|
@@ -225,21 +251,21 @@ function shutdownServers(exitCode: number): void {
|
|
|
225
251
|
if (httpServer) {
|
|
226
252
|
httpServer.close(function () {
|
|
227
253
|
console.log('Http server shut down')
|
|
228
|
-
|
|
254
|
+
exitProcess(exitCode)
|
|
229
255
|
})
|
|
230
256
|
} else {
|
|
231
|
-
|
|
257
|
+
exitProcess(exitCode)
|
|
232
258
|
}
|
|
233
259
|
}
|
|
234
260
|
|
|
235
261
|
// Multi-worker mode: spawn child processes for additional servers
|
|
236
262
|
if (options.worker > 1 && !isChildProcess) {
|
|
237
|
-
const childProcesses
|
|
263
|
+
const childProcesses = new Map<number, ChildProcess>()
|
|
264
|
+
const restartTimers = new Map<number, NodeJS.Timeout>()
|
|
238
265
|
const basePort = parseInt(options.port)
|
|
266
|
+
const restartDelayMs = 1000
|
|
239
267
|
|
|
240
|
-
|
|
241
|
-
for (let i = 1; i < options.worker; i++) {
|
|
242
|
-
const childPort = basePort + i
|
|
268
|
+
const spawnChild = (childPort: number): void => {
|
|
243
269
|
const args = process.argv.slice(2)
|
|
244
270
|
const childArgs: string[] = ['--port=' + String(childPort)]
|
|
245
271
|
// Ignore port argument for child process
|
|
@@ -256,6 +282,7 @@ if (options.worker > 1 && !isChildProcess) {
|
|
|
256
282
|
|
|
257
283
|
childArgs.push(arg)
|
|
258
284
|
}
|
|
285
|
+
|
|
259
286
|
const child = fork(fileURLToPath(import.meta.url), childArgs, {
|
|
260
287
|
env: {
|
|
261
288
|
...process.env,
|
|
@@ -268,21 +295,54 @@ if (options.worker > 1 && !isChildProcess) {
|
|
|
268
295
|
console.error(`Child process on port ${childPort} error:`, err)
|
|
269
296
|
})
|
|
270
297
|
|
|
271
|
-
child.on('exit', (code) => {
|
|
272
|
-
|
|
298
|
+
child.on('exit', (code, signal) => {
|
|
299
|
+
childProcesses.delete(childPort)
|
|
300
|
+
console.log(`Child process on port ${childPort} exited with code ${code}, signal ${signal ?? 'none'}`)
|
|
301
|
+
|
|
302
|
+
const isNormalShutdown = signal === null && code === 0
|
|
303
|
+
if (isParentShuttingDown || isNormalShutdown) {
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (restartTimers.has(childPort)) {
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
console.log(`Scheduling restart for child process on port ${childPort} in ${restartDelayMs}ms`)
|
|
312
|
+
const timer = setTimeout(() => {
|
|
313
|
+
restartTimers.delete(childPort)
|
|
314
|
+
if (isParentShuttingDown) {
|
|
315
|
+
return
|
|
316
|
+
}
|
|
317
|
+
console.log(`Restarting child process on port ${childPort}`)
|
|
318
|
+
spawnChild(childPort)
|
|
319
|
+
}, restartDelayMs)
|
|
320
|
+
restartTimers.set(childPort, timer)
|
|
273
321
|
})
|
|
274
322
|
|
|
275
|
-
childProcesses.
|
|
276
|
-
console.log(`Spawned child server process for port ${childPort}`)
|
|
323
|
+
childProcesses.set(childPort, child)
|
|
324
|
+
console.log(`Spawned child server process for port ${childPort} (pid: ${child.pid})`)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Spawn child processes for ports basePort+1 to basePort+(worker-1)
|
|
328
|
+
for (let i = 1; i < options.worker; i++) {
|
|
329
|
+
const childPort = basePort + i
|
|
330
|
+
spawnChild(childPort)
|
|
277
331
|
}
|
|
278
332
|
|
|
279
333
|
// Handle parent process shutdown - kill all children
|
|
280
|
-
|
|
281
|
-
|
|
334
|
+
shutdownChildren = () => {
|
|
335
|
+
if (areChildrenShuttingDown) {
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
areChildrenShuttingDown = true
|
|
339
|
+
isParentShuttingDown = true
|
|
340
|
+
for (const timer of restartTimers.values()) {
|
|
341
|
+
clearTimeout(timer)
|
|
342
|
+
}
|
|
343
|
+
restartTimers.clear()
|
|
344
|
+
for (const child of childProcesses.values()) {
|
|
282
345
|
child.kill('SIGINT')
|
|
283
346
|
}
|
|
284
347
|
}
|
|
285
|
-
|
|
286
|
-
process.on('SIGINT', shutdownChildren)
|
|
287
|
-
process.on('SIGTERM', shutdownChildren)
|
|
288
348
|
}
|