@sentio/runtime 2.57.12-rc.d → 2.57.12-rc.f
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-CPC37CZL.js → chunk-IAGVEBAE.js} +1796 -5191
- package/lib/chunk-IAGVEBAE.js.map +1 -0
- package/lib/{chunk-6YBY6GSE.js → chunk-XR3EZ6FB.js} +448 -479
- package/lib/chunk-XR3EZ6FB.js.map +1 -0
- package/lib/index.d.ts +50 -136
- package/lib/index.js +2 -2
- package/lib/processor-runner.js +758 -1160
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.js +34 -29
- package/lib/service-worker.js.map +1 -1
- package/package.json +1 -1
- package/src/service-manager.ts +3 -3
- package/src/service-worker.ts +33 -28
- package/lib/chunk-6YBY6GSE.js.map +0 -1
- package/lib/chunk-CPC37CZL.js.map +0 -1
package/lib/service-worker.js
CHANGED
@@ -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-
|
8
|
+
} from "./chunk-IAGVEBAE.js";
|
9
9
|
import {
|
10
10
|
PluginManager,
|
11
11
|
ProcessConfigResponse,
|
12
12
|
__toESM
|
13
|
-
} from "./chunk-
|
13
|
+
} from "./chunk-XR3EZ6FB.js";
|
14
14
|
|
15
15
|
// src/service-worker.ts
|
16
16
|
var import_nice_grpc = __toESM(require_lib(), 1);
|
@@ -40,7 +40,7 @@ async function getConfig(request, context) {
|
|
40
40
|
var loader = async (options) => {
|
41
41
|
if (options.target) {
|
42
42
|
const m = await import(options.target);
|
43
|
-
console.debug("Module loaded", m);
|
43
|
+
console.debug("Module loaded, path:", options.target, "module:", m);
|
44
44
|
return m;
|
45
45
|
}
|
46
46
|
};
|
@@ -59,39 +59,44 @@ async function start(request, options) {
|
|
59
59
|
throw new import_nice_grpc.ServerError(import_nice_grpc.Status.INVALID_ARGUMENT, "Failed to load processor: " + errorString(e));
|
60
60
|
}
|
61
61
|
await PluginManager.INSTANCE.start(request);
|
62
|
+
started = true;
|
62
63
|
return {};
|
63
64
|
}
|
64
65
|
async function service_worker_default({ request }) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
try {
|
67
|
+
if (!started) {
|
68
|
+
const { startRequest, configRequest, options } = Piscina.workerData;
|
69
|
+
if (startRequest) {
|
70
|
+
await start(startRequest, options);
|
71
|
+
}
|
72
|
+
if (configRequest) {
|
73
|
+
await getConfig(configRequest);
|
74
|
+
}
|
75
|
+
console.info("new processor worker started");
|
69
76
|
}
|
70
|
-
if (
|
71
|
-
|
77
|
+
if (unhandled) {
|
78
|
+
throw new import_nice_grpc_error_details.RichServerError(
|
79
|
+
import_nice_grpc.Status.UNAVAILABLE,
|
80
|
+
"Unhandled exception/rejection in previous request: " + errorString(unhandled),
|
81
|
+
[
|
82
|
+
import_nice_grpc_error_details.DebugInfo.fromPartial({
|
83
|
+
detail: unhandled.message,
|
84
|
+
stackEntries: unhandled.stack?.split("\n")
|
85
|
+
})
|
86
|
+
]
|
87
|
+
);
|
72
88
|
}
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
]
|
89
|
+
const result = await PluginManager.INSTANCE.processBinding(
|
90
|
+
request,
|
91
|
+
void 0
|
92
|
+
// PluginManager.INSTANCE.dbContextLocalStorage.getStore()
|
86
93
|
);
|
94
|
+
recordRuntimeInfo(result, request.handlerType);
|
95
|
+
return result;
|
96
|
+
} catch (e) {
|
97
|
+
console.error("worker process binding failed", e);
|
98
|
+
throw e;
|
87
99
|
}
|
88
|
-
const result = await PluginManager.INSTANCE.processBinding(
|
89
|
-
request,
|
90
|
-
void 0
|
91
|
-
// PluginManager.INSTANCE.dbContextLocalStorage.getStore()
|
92
|
-
);
|
93
|
-
recordRuntimeInfo(result, request.handlerType);
|
94
|
-
return result;
|
95
100
|
}
|
96
101
|
import("node:process").then((p) => p.stdout.write(""));
|
97
102
|
export {
|
@@ -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', 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 return {}\n}\n\nexport default async function ({ request }: { request: DataBinding }) {\n if (!started) {\n
|
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 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 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;AA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;AAAA,YAClB,cAAc,UAAU,OAAO,MAAM,IAAI;AAAA,UAC3C,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":[]}
|
package/package.json
CHANGED
package/src/service-manager.ts
CHANGED
@@ -156,7 +156,7 @@ export class ServiceManager implements ProcessorServiceImplementation {
|
|
156
156
|
)
|
157
157
|
}
|
158
158
|
|
159
|
-
return
|
159
|
+
return this.pool.run({ request })
|
160
160
|
}
|
161
161
|
|
162
162
|
async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
|
@@ -199,7 +199,7 @@ export class ServiceManager implements ProcessorServiceImplementation {
|
|
199
199
|
|
200
200
|
const binding = request.binding
|
201
201
|
// todo support db request
|
202
|
-
|
202
|
+
const dbContext = contexts.new(request.processId, subject)
|
203
203
|
const start = Date.now()
|
204
204
|
await this.processBinding(binding)
|
205
205
|
.then(async (result) => {
|
@@ -212,7 +212,7 @@ export class ServiceManager implements ProcessorServiceImplementation {
|
|
212
212
|
})
|
213
213
|
.catch((e) => {
|
214
214
|
console.debug(e)
|
215
|
-
|
215
|
+
dbContext.error(request.processId, e)
|
216
216
|
process_binding_error.add(1)
|
217
217
|
})
|
218
218
|
.finally(() => {
|
package/src/service-worker.ts
CHANGED
@@ -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', m)
|
54
|
+
console.debug('Module loaded, path:', options.target, 'module:', m)
|
55
55
|
return m
|
56
56
|
}
|
57
57
|
}
|
@@ -74,40 +74,45 @@ async function start(request: StartRequest, options: any): Promise<Empty> {
|
|
74
74
|
}
|
75
75
|
|
76
76
|
await PluginManager.INSTANCE.start(request)
|
77
|
+
started = true
|
77
78
|
return {}
|
78
79
|
}
|
79
80
|
|
80
81
|
export default async function ({ request }: { request: DataBinding }) {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
try {
|
83
|
+
if (!started) {
|
84
|
+
const { startRequest, configRequest, options } = Piscina.workerData
|
85
|
+
if (startRequest) {
|
86
|
+
await start(startRequest, options)
|
87
|
+
}
|
88
|
+
if (configRequest) {
|
89
|
+
await getConfig(configRequest)
|
90
|
+
}
|
91
|
+
console.info('new processor worker started')
|
85
92
|
}
|
86
|
-
|
87
|
-
|
93
|
+
|
94
|
+
if (unhandled) {
|
95
|
+
throw new RichServerError(
|
96
|
+
Status.UNAVAILABLE,
|
97
|
+
'Unhandled exception/rejection in previous request: ' + errorString(unhandled),
|
98
|
+
[
|
99
|
+
DebugInfo.fromPartial({
|
100
|
+
detail: unhandled.message,
|
101
|
+
stackEntries: unhandled.stack?.split('\n')
|
102
|
+
})
|
103
|
+
]
|
104
|
+
)
|
88
105
|
}
|
89
|
-
started = true
|
90
|
-
console.info('new processor worker started')
|
91
|
-
}
|
92
106
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
[
|
98
|
-
DebugInfo.fromPartial({
|
99
|
-
detail: unhandled.message,
|
100
|
-
stackEntries: unhandled.stack?.split('\n')
|
101
|
-
})
|
102
|
-
]
|
107
|
+
const result = await PluginManager.INSTANCE.processBinding(
|
108
|
+
request,
|
109
|
+
undefined
|
110
|
+
// PluginManager.INSTANCE.dbContextLocalStorage.getStore()
|
103
111
|
)
|
112
|
+
recordRuntimeInfo(result, request.handlerType)
|
113
|
+
return result
|
114
|
+
} catch (e) {
|
115
|
+
console.error('worker process binding failed', e)
|
116
|
+
throw e
|
104
117
|
}
|
105
|
-
|
106
|
-
const result = await PluginManager.INSTANCE.processBinding(
|
107
|
-
request,
|
108
|
-
undefined
|
109
|
-
// PluginManager.INSTANCE.dbContextLocalStorage.getStore()
|
110
|
-
)
|
111
|
-
recordRuntimeInfo(result, request.handlerType)
|
112
|
-
return result
|
113
118
|
}
|