@sentio/runtime 2.44.5-rc.2 → 2.44.6-rc.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/lib/{chunk-MHFCQFYK.js → chunk-LC6Z2ZSV.js} +2 -2
- package/lib/{chunk-MHFCQFYK.js.map → chunk-LC6Z2ZSV.js.map} +1 -1
- package/lib/index.d.ts +11 -6
- package/lib/index.js +1 -1
- package/lib/processor-runner.js +29 -29
- package/lib/processor-runner.js.map +1 -1
- package/package.json +1 -1
- package/src/action-server.ts +18 -0
- package/src/plugin.ts +17 -7
- package/src/processor-runner.ts +11 -20
package/package.json
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
import { PluginManager } from './plugin.js'
|
2
|
+
import { ProcessConfigResponse } from '@sentio/protos'
|
3
|
+
|
4
|
+
export class ActionServer {
|
5
|
+
constructor(readonly loader: () => Promise<void>) {}
|
6
|
+
|
7
|
+
async listen(port: number) {
|
8
|
+
const pluginManager = PluginManager.INSTANCE
|
9
|
+
await this.loader()
|
10
|
+
await pluginManager.configure(ProcessConfigResponse.create())
|
11
|
+
console.log('Starting Action Server at:', port)
|
12
|
+
await pluginManager.startServer(port)
|
13
|
+
}
|
14
|
+
|
15
|
+
forceShutdown() {
|
16
|
+
PluginManager.INSTANCE.shutdown()
|
17
|
+
}
|
18
|
+
}
|
package/src/plugin.ts
CHANGED
@@ -15,13 +15,8 @@ export abstract class Plugin {
|
|
15
15
|
supportedHandlers: HandlerType[] = []
|
16
16
|
|
17
17
|
async configure(config: ProcessConfigResponse): Promise<void> {}
|
18
|
-
async start(start: StartRequest, actionServerPort?: number): Promise<void> {}
|
19
18
|
|
20
|
-
|
21
|
-
* method used by action server only
|
22
|
-
* @param port
|
23
|
-
*/
|
24
|
-
async startServer(port?: number): Promise<void> {}
|
19
|
+
async start(start: StartRequest): Promise<void> {}
|
25
20
|
|
26
21
|
/**
|
27
22
|
* @deprecated The method should not be used, use ctx.states instead
|
@@ -37,6 +32,17 @@ export abstract class Plugin {
|
|
37
32
|
async preprocessBinding(request: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
|
38
33
|
return PreprocessResult.create()
|
39
34
|
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* method used by action server only
|
38
|
+
* @param port
|
39
|
+
*/
|
40
|
+
async startServer(port?: number): Promise<void> {}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* method used by action server only
|
44
|
+
*/
|
45
|
+
shutdownServer() {}
|
40
46
|
}
|
41
47
|
|
42
48
|
export class PluginManager {
|
@@ -66,13 +72,17 @@ export class PluginManager {
|
|
66
72
|
}
|
67
73
|
|
68
74
|
start(start: StartRequest, actionServerPort?: number) {
|
69
|
-
return Promise.all(this.plugins.map((plugin) => plugin.start(start
|
75
|
+
return Promise.all(this.plugins.map((plugin) => plugin.start(start)))
|
70
76
|
}
|
71
77
|
|
72
78
|
startServer(port?: number) {
|
73
79
|
return Promise.all(this.plugins.map((plugin) => plugin.startServer(port)))
|
74
80
|
}
|
75
81
|
|
82
|
+
shutdown() {
|
83
|
+
this.plugins.forEach((plugin) => plugin.shutdownServer())
|
84
|
+
}
|
85
|
+
|
76
86
|
/**
|
77
87
|
* @deprecated The method should not be used, use ctx.states instead
|
78
88
|
*/
|
package/src/processor-runner.ts
CHANGED
@@ -5,7 +5,7 @@ import fs from 'fs-extra'
|
|
5
5
|
|
6
6
|
import { compressionAlgorithms } from '@grpc/grpc-js'
|
7
7
|
import commandLineArgs from 'command-line-args'
|
8
|
-
import { createServer
|
8
|
+
import { createServer } from 'nice-grpc'
|
9
9
|
import { errorDetailsServerMiddleware } from 'nice-grpc-error-details'
|
10
10
|
// import { registry as niceGrpcRegistry } from 'nice-grpc-prometheus'
|
11
11
|
import { openTelemetryServerMiddleware } from 'nice-grpc-opentelemetry'
|
@@ -21,8 +21,7 @@ import { ChainConfig } from './chain-config.js'
|
|
21
21
|
import { setupLogger } from './logger.js'
|
22
22
|
|
23
23
|
import { setupOTLP } from './otlp.js'
|
24
|
-
import {
|
25
|
-
import { ProcessConfigResponse } from '@sentio/protos'
|
24
|
+
import { ActionServer } from './action-server.js'
|
26
25
|
|
27
26
|
// const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])
|
28
27
|
|
@@ -87,20 +86,16 @@ for (const [id, config] of Object.entries(chainsConfig)) {
|
|
87
86
|
|
88
87
|
console.debug('Starting Server', options)
|
89
88
|
|
90
|
-
let server:
|
89
|
+
let server: any
|
91
90
|
let baseService: ProcessorServiceImpl
|
92
|
-
|
91
|
+
const loader = async () => {
|
92
|
+
const m = await import(options.target)
|
93
|
+
console.debug('Module loaded', m)
|
94
|
+
return m
|
95
|
+
}
|
93
96
|
if (options['start-action-server']) {
|
94
|
-
|
95
|
-
|
96
|
-
.configure(ProcessConfigResponse.create())
|
97
|
-
.then(() => {
|
98
|
-
console.log('Starting Action Server at:', options.port)
|
99
|
-
return pluginManager.startServer(options.port)
|
100
|
-
})
|
101
|
-
.catch((err) => {
|
102
|
-
console.error('Error starting action server', err)
|
103
|
-
})
|
97
|
+
server = new ActionServer(loader)
|
98
|
+
server.listen(options.port)
|
104
99
|
} else {
|
105
100
|
server = createServer({
|
106
101
|
'grpc.max_send_message_length': 384 * 1024 * 1024,
|
@@ -110,11 +105,7 @@ if (options['start-action-server']) {
|
|
110
105
|
// .use(prometheusServerMiddleware())
|
111
106
|
.use(openTelemetryServerMiddleware())
|
112
107
|
.use(errorDetailsServerMiddleware)
|
113
|
-
baseService = new ProcessorServiceImpl(
|
114
|
-
const m = await import(options.target)
|
115
|
-
console.debug('Module loaded', m)
|
116
|
-
return m
|
117
|
-
}, server.shutdown)
|
108
|
+
baseService = new ProcessorServiceImpl(loader, server.shutdown)
|
118
109
|
const service = new FullProcessorServiceImpl(baseService)
|
119
110
|
|
120
111
|
server.add(ProcessorDefinition, service)
|