@sentio/runtime 2.57.12-rc.e → 2.57.12-rc.g

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.
@@ -5,12 +5,12 @@ import {
5
5
  recordRuntimeInfo,
6
6
  require_lib2 as require_lib,
7
7
  require_lib3 as require_lib2
8
- } from "./chunk-YVOMEKB4.js";
8
+ } from "./chunk-IAGVEBAE.js";
9
9
  import {
10
10
  PluginManager,
11
11
  ProcessConfigResponse,
12
12
  __toESM
13
- } from "./chunk-6YBY6GSE.js";
13
+ } from "./chunk-XR3EZ6FB.js";
14
14
 
15
15
  // src/service-worker.ts
16
16
  var import_nice_grpc = __toESM(require_lib(), 1);
@@ -63,29 +63,31 @@ async function start(request, options) {
63
63
  return {};
64
64
  }
65
65
  async function service_worker_default({ request }) {
66
- if (!started) {
66
+ try {
67
67
  const { startRequest, configRequest, options } = Piscina.workerData;
68
- if (startRequest) {
69
- await start(startRequest, options);
68
+ if (!started) {
69
+ if (startRequest) {
70
+ await start(startRequest, options);
71
+ console.info("worker started");
72
+ }
73
+ console.info("new processor worker started");
74
+ if (configRequest) {
75
+ await getConfig(configRequest);
76
+ console.info("worker configured");
77
+ }
70
78
  }
71
- if (configRequest) {
72
- await getConfig(configRequest);
79
+ if (unhandled) {
80
+ throw new import_nice_grpc_error_details.RichServerError(
81
+ import_nice_grpc.Status.UNAVAILABLE,
82
+ "Unhandled exception/rejection in previous request: " + errorString(unhandled),
83
+ [
84
+ import_nice_grpc_error_details.DebugInfo.fromPartial({
85
+ detail: unhandled.message,
86
+ stackEntries: unhandled.stack?.split("\n")
87
+ })
88
+ ]
89
+ );
73
90
  }
74
- console.info("new processor worker started");
75
- }
76
- if (unhandled) {
77
- throw new import_nice_grpc_error_details.RichServerError(
78
- import_nice_grpc.Status.UNAVAILABLE,
79
- "Unhandled exception/rejection in previous request: " + errorString(unhandled),
80
- [
81
- import_nice_grpc_error_details.DebugInfo.fromPartial({
82
- detail: unhandled.message,
83
- stackEntries: unhandled.stack?.split("\n")
84
- })
85
- ]
86
- );
87
- }
88
- try {
89
91
  const result = await PluginManager.INSTANCE.processBinding(
90
92
  request,
91
93
  void 0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import {\n DataBinding,\n Empty,\n HandlerType,\n PreparedData,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest\n} from '@sentio/protos'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { PluginManager } from './plugin.js'\nimport commandLineArgs from 'command-line-args'\nimport { optionDefinitions } from './processor-runner.js'\nimport { errorString } from './utils.js'\nimport { freezeGlobalConfig } from './global-config.js'\nimport { DebugInfo, RichServerError } from 'nice-grpc-error-details'\nimport { recordRuntimeInfo } from './service.js'\nimport { BroadcastChannel } from 'worker_threads'\nimport { Piscina } from 'piscina'\n\nlet started = false\n\nlet unhandled: Error | undefined\n\nprocess\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n unhandled = err\n })\n .on('unhandledRejection', (reason, p) => {\n // @ts-ignore ignore invalid ens error\n if (reason?.message.startsWith('invalid ENS name (disallowed character: \"*\"')) {\n return\n }\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n unhandled = reason as Error\n // shutdownServers(1)\n })\n\nasync function getConfig(request: ProcessConfigRequest, context?: CallContext): Promise<ProcessConfigResponse> {\n if (!started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const newConfig = ProcessConfigResponse.fromPartial({})\n await PluginManager.INSTANCE.configure(newConfig)\n return newConfig\n}\n\nconst loader = async (options: any) => {\n if (options.target) {\n const m = await import(options.target)\n console.debug('Module loaded, path:', options.target, \"module:\", m)\n return m\n }\n}\n\nconst configureChannel = new BroadcastChannel('configure_channel')\nconfigureChannel.onmessage = (request: ProcessConfigRequest) => {\n getConfig(request)\n}\n\nasync function start(request: StartRequest, options: any): Promise<Empty> {\n if (started) {\n return {}\n }\n freezeGlobalConfig()\n\n try {\n await loader(options)\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await PluginManager.INSTANCE.start(request)\n started = true\n return {}\n}\n\nexport default async function ({ request }: { request: DataBinding }) {\n if (!started) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (startRequest) {\n await start(startRequest, options)\n }\n if (configRequest) {\n await getConfig(configRequest)\n }\n console.info('new processor worker started')\n }\n\n if (unhandled) {\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(unhandled),\n [\n DebugInfo.fromPartial({\n detail: unhandled.message,\n stackEntries: unhandled.stack?.split('\\n')\n })\n ]\n )\n }\n\n try {\n const result = await PluginManager.INSTANCE.processBinding(\n request,\n undefined\n // PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n )\n recordRuntimeInfo(result, request.handlerType)\n return result\n } catch (e) {\n console.error(\"worker process binding failed\", e)\n throw e\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;;;;;;;;;;AAUA,uBAAiD;AAMjD,qCAA2C;AAE3C,SAAS,wBAAwB;AACjC,SAAS,eAAe;AAExB,IAAI,UAAU;AAEd,IAAI;AAEJ,QACG,GAAG,qBAAqB,CAAC,QAAQ;AAChC,UAAQ,MAAM,iEAAiE,GAAG;AAClF,cAAY;AACd,CAAC,EACA,GAAG,sBAAsB,CAAC,QAAQ,MAAM;AAEvC,MAAI,QAAQ,QAAQ,WAAW,6CAA6C,GAAG;AAC7E;AAAA,EACF;AACA,UAAQ,MAAM,6DAA6D,MAAM;AACjF,cAAY;AAEd,CAAC;AAEH,eAAe,UAAU,SAA+B,SAAuD;AAC7G,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,6BAAY,wBAAO,aAAa,sBAAsB;AAAA,EAClE;AAEA,QAAM,YAAY,sBAAsB,YAAY,CAAC,CAAC;AACtD,QAAM,cAAc,SA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,QAAQ,WAAW;AAC7C,WAAO;AAAA,EACT,SAAS,GAAG;AACV,YAAQ,MAAM,iCAAiC,CAAC;AAChD,UAAM;AAAA,EACR;AACF;AACC,OAAO,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import {\n DataBinding,\n Empty,\n HandlerType,\n PreparedData,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest\n} from '@sentio/protos'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { PluginManager } from './plugin.js'\nimport commandLineArgs from 'command-line-args'\nimport { optionDefinitions } from './processor-runner.js'\nimport { errorString } from './utils.js'\nimport { freezeGlobalConfig } from './global-config.js'\nimport { DebugInfo, RichServerError } from 'nice-grpc-error-details'\nimport { recordRuntimeInfo } from './service.js'\nimport { BroadcastChannel } from 'worker_threads'\nimport { Piscina } from 'piscina'\n\nlet started = false\n\nlet unhandled: Error | undefined\n\nprocess\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n unhandled = err\n })\n .on('unhandledRejection', (reason, p) => {\n // @ts-ignore ignore invalid ens error\n if (reason?.message.startsWith('invalid ENS name (disallowed character: \"*\"')) {\n return\n }\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n unhandled = reason as Error\n // shutdownServers(1)\n })\n\nasync function getConfig(request: ProcessConfigRequest, context?: CallContext): Promise<ProcessConfigResponse> {\n if (!started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const newConfig = ProcessConfigResponse.fromPartial({})\n await PluginManager.INSTANCE.configure(newConfig)\n return newConfig\n}\n\nconst loader = async (options: any) => {\n if (options.target) {\n const m = await import(options.target)\n console.debug('Module loaded, path:', options.target, 'module:', m)\n return m\n }\n}\n\nconst configureChannel = new BroadcastChannel('configure_channel')\nconfigureChannel.onmessage = (request: ProcessConfigRequest) => {\n getConfig(request)\n}\n\nasync function start(request: StartRequest, options: any): Promise<Empty> {\n if (started) {\n return {}\n }\n freezeGlobalConfig()\n\n try {\n await loader(options)\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await PluginManager.INSTANCE.start(request)\n started = true\n return {}\n}\n\nexport default async function ({ request }: { request: DataBinding }) {\n try {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n if (startRequest) {\n await start(startRequest, options)\n console.info('worker started')\n }\n console.info('new processor worker started')\n\n if (configRequest) {\n await getConfig(configRequest)\n console.info('worker configured')\n }\n }\n\n if (unhandled) {\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(unhandled),\n [\n DebugInfo.fromPartial({\n detail: unhandled.message,\n stackEntries: unhandled.stack?.split('\\n')\n })\n ]\n )\n }\n\n const result = await PluginManager.INSTANCE.processBinding(\n request,\n undefined\n // PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n )\n recordRuntimeInfo(result, request.handlerType)\n return result\n } catch (e) {\n console.error('worker process binding failed', e)\n throw e\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;;;;;;;;;;AAUA,uBAAiD;AAMjD,qCAA2C;AAE3C,SAAS,wBAAwB;AACjC,SAAS,eAAe;AAExB,IAAI,UAAU;AAEd,IAAI;AAEJ,QACG,GAAG,qBAAqB,CAAC,QAAQ;AAChC,UAAQ,MAAM,iEAAiE,GAAG;AAClF,cAAY;AACd,CAAC,EACA,GAAG,sBAAsB,CAAC,QAAQ,MAAM;AAEvC,MAAI,QAAQ,QAAQ,WAAW,6CAA6C,GAAG;AAC7E;AAAA,EACF;AACA,UAAQ,MAAM,6DAA6D,MAAM;AACjF,cAAY;AAEd,CAAC;AAEH,eAAe,UAAU,SAA+B,SAAuD;AAC7G,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,6BAAY,wBAAO,aAAa,sBA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AC3C,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,cAAc,SAAS;AAAA,MAC1C;AAAA,MACA;AAAA;AAAA,IAEF;AACA,sBAAkB,QAAQ,QAAQ,WAAW;AAC7C,WAAO;AAAA,EACT,SAAS,GAAG;AACV,YAAQ,MAAM,iCAAiC,CAAC;AAChD,UAAM;AAAA,EACR;AACF;AACC,OAAO,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;","names":[]}
@@ -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'\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.APT_EVENT]\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;;;AAGA,IAAM,aAAN,cAAyB,OAAO;AAAA,EAC9B,MAAM,eAAe,SAA8C;AACjE,WAAO,cAAc,YAAY;AAAA,MAC/B,QAAQ;AAAA,QACN,eAAe;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,oBAAoB,mCAA2C;AACjE;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":[]}
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'\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN]\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;;;AAGA,IAAM,aAAN,cAAyB,OAAO;AAAA,EAC9B,MAAM,eAAe,SAA8C;AACjE,WAAO,cAAc,YAAY;AAAA,MAC/B,QAAQ;AAAA,QACN,eAAe;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,oBAAoB,gBAAoB;AAC1C;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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.57.12-rc.e",
3
+ "version": "2.57.12-rc.g",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -44,11 +44,15 @@ export class ServiceManager implements ProcessorServiceImplementation {
44
44
  // private processorConfig: ProcessConfigResponse
45
45
  private pool: Piscina<any, any>
46
46
 
47
+ private workerData: any = {}
48
+
47
49
  constructor(
48
50
  readonly options: any,
49
51
  readonly loader: () => Promise<any>,
50
52
  readonly shutdownHandler?: () => void
51
- ) {}
53
+ ) {
54
+ this.workerData.options = options
55
+ }
52
56
 
53
57
  async *preprocessBindingsStream(requests: AsyncIterable<PreprocessStreamRequest>, context: CallContext) {
54
58
  throw new Error('not supported')
@@ -66,10 +70,8 @@ export class ServiceManager implements ProcessorServiceImplementation {
66
70
  // also configure the main thread
67
71
  const newConfig = ProcessConfigResponse.fromPartial({})
68
72
  await PluginManager.INSTANCE.configure(newConfig)
69
- this.pool.options.workerData = {
70
- configRequest: request,
71
- ...this.pool.options.workerData
72
- }
73
+
74
+ this.workerData.configRequest = request
73
75
  return newConfig
74
76
  }
75
77
 
@@ -84,26 +86,17 @@ export class ServiceManager implements ProcessorServiceImplementation {
84
86
  throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))
85
87
  }
86
88
 
87
- this.pool = new Piscina({
88
- maxThreads: this.options.worker,
89
- minThreads: this.options.worker,
90
- filename: new URL('./service-worker.js', import.meta.url).href.replaceAll('runtime/src', 'runtime/lib'),
91
- argv: process.argv,
92
- workerData: {
93
- startRequest: request,
94
- options: this.options
95
- }
96
- })
97
-
98
89
  // also start the processor in main thread
99
90
  await PluginManager.INSTANCE.start(request)
100
91
  this.started = true
92
+ this.workerData.startRequest = request
101
93
  return {}
102
94
  }
103
95
 
104
96
  async stop(request: Empty, context: CallContext): Promise<Empty> {
105
- console.log('Server Shutting down in 5 seconds')
97
+ await this.pool.destroy()
106
98
  if (this.shutdownHandler) {
99
+ console.log('Server Shutting down in 5 seconds')
107
100
  setTimeout(this.shutdownHandler, 5000)
108
101
  }
109
102
  return {}
@@ -143,6 +136,15 @@ export class ServiceManager implements ProcessorServiceImplementation {
143
136
  if (!this.started) {
144
137
  throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
145
138
  }
139
+ if (!this.pool) {
140
+ this.pool = new Piscina({
141
+ maxThreads: this.options.worker,
142
+ minThreads: this.options.worker,
143
+ filename: new URL('./service-worker.js', import.meta.url).href.replaceAll('runtime/src', 'runtime/lib'),
144
+ argv: process.argv,
145
+ workerData: this.workerData
146
+ })
147
+ }
146
148
  if (this.unhandled) {
147
149
  throw new RichServerError(
148
150
  Status.UNAVAILABLE,
@@ -199,7 +201,7 @@ export class ServiceManager implements ProcessorServiceImplementation {
199
201
 
200
202
  const binding = request.binding
201
203
  // todo support db request
202
- // const dbContext = contexts.new(request.processId, subject)
204
+ const dbContext = contexts.new(request.processId, subject)
203
205
  const start = Date.now()
204
206
  await this.processBinding(binding)
205
207
  .then(async (result) => {
@@ -212,7 +214,7 @@ export class ServiceManager implements ProcessorServiceImplementation {
212
214
  })
213
215
  .catch((e) => {
214
216
  console.debug(e)
215
- // dbContext.error(request.processId, e)
217
+ dbContext.error(request.processId, e)
216
218
  process_binding_error.add(1)
217
219
  })
218
220
  .finally(() => {
@@ -51,7 +51,7 @@ async function getConfig(request: ProcessConfigRequest, context?: CallContext):
51
51
  const loader = async (options: any) => {
52
52
  if (options.target) {
53
53
  const m = await import(options.target)
54
- console.debug('Module loaded, path:', options.target, "module:", m)
54
+ console.debug('Module loaded, path:', options.target, 'module:', m)
55
55
  return m
56
56
  }
57
57
  }
@@ -79,31 +79,34 @@ async function start(request: StartRequest, options: any): Promise<Empty> {
79
79
  }
80
80
 
81
81
  export default async function ({ request }: { request: DataBinding }) {
82
- if (!started) {
82
+ try {
83
83
  const { startRequest, configRequest, options } = Piscina.workerData
84
- if (startRequest) {
85
- await start(startRequest, options)
86
- }
87
- if (configRequest) {
88
- await getConfig(configRequest)
84
+ if (!started) {
85
+ if (startRequest) {
86
+ await start(startRequest, options)
87
+ console.info('worker started')
88
+ }
89
+ console.info('new processor worker started')
90
+
91
+ if (configRequest) {
92
+ await getConfig(configRequest)
93
+ console.info('worker configured')
94
+ }
89
95
  }
90
- console.info('new processor worker started')
91
- }
92
96
 
93
- if (unhandled) {
94
- throw new RichServerError(
95
- Status.UNAVAILABLE,
96
- 'Unhandled exception/rejection in previous request: ' + errorString(unhandled),
97
- [
98
- DebugInfo.fromPartial({
99
- detail: unhandled.message,
100
- stackEntries: unhandled.stack?.split('\n')
101
- })
102
- ]
103
- )
104
- }
97
+ if (unhandled) {
98
+ throw new RichServerError(
99
+ Status.UNAVAILABLE,
100
+ 'Unhandled exception/rejection in previous request: ' + errorString(unhandled),
101
+ [
102
+ DebugInfo.fromPartial({
103
+ detail: unhandled.message,
104
+ stackEntries: unhandled.stack?.split('\n')
105
+ })
106
+ ]
107
+ )
108
+ }
105
109
 
106
- try {
107
110
  const result = await PluginManager.INSTANCE.processBinding(
108
111
  request,
109
112
  undefined
@@ -112,7 +115,7 @@ export default async function ({ request }: { request: DataBinding }) {
112
115
  recordRuntimeInfo(result, request.handlerType)
113
116
  return result
114
117
  } catch (e) {
115
- console.error("worker process binding failed", e)
118
+ console.error('worker process binding failed', e)
116
119
  throw e
117
120
  }
118
121
  }