@sentio/runtime 2.39.3 → 2.39.4-rc.10
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/db-context.d.ts +5 -131
- package/lib/db-context.d.ts.map +1 -1
- package/lib/db-context.js +11 -9
- package/lib/db-context.js.map +1 -1
- package/lib/endpoints.d.ts +1 -0
- package/lib/endpoints.d.ts.map +1 -1
- package/lib/endpoints.js +1 -0
- package/lib/endpoints.js.map +1 -1
- package/lib/full-service.d.ts +55 -2
- package/lib/full-service.d.ts.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +59 -15
- package/lib/gen/processor/protos/processor.d.ts.map +1 -1
- package/lib/gen/processor/protos/processor.js +408 -88
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/gen/service/common/protos/common.d.ts +97 -0
- package/lib/gen/service/common/protos/common.d.ts.map +1 -1
- package/lib/gen/service/common/protos/common.js +624 -0
- package/lib/gen/service/common/protos/common.js.map +1 -1
- package/lib/processor-runner.js +2 -0
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.d.ts +56 -2
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +36 -28
- package/lib/service.js.map +1 -1
- package/package.json +2 -2
- package/src/db-context.ts +9 -7
- package/src/endpoints.ts +2 -0
- package/src/gen/processor/protos/processor.ts +465 -103
- package/src/gen/service/common/protos/common.ts +727 -0
- package/src/processor-runner.ts +2 -0
- package/src/service.ts +44 -28
package/src/processor-runner.ts
CHANGED
@@ -26,6 +26,7 @@ const optionDefinitions = [
|
|
26
26
|
{ name: 'target', type: String, defaultOption: true },
|
27
27
|
{ name: 'port', alias: 'p', type: String, defaultValue: '4000' },
|
28
28
|
{ name: 'concurrency', type: Number, defaultValue: 4 },
|
29
|
+
{ name: 'batch-count', type: Number, defaultValue: 1 },
|
29
30
|
// { name: 'use-chainserver', type: Boolean, defaultValue: false },
|
30
31
|
{
|
31
32
|
name: 'chains-config',
|
@@ -50,6 +51,7 @@ const fullPath = path.resolve(options['chains-config'])
|
|
50
51
|
const chainsConfig = fs.readJsonSync(fullPath)
|
51
52
|
|
52
53
|
Endpoints.INSTANCE.concurrency = options.concurrency
|
54
|
+
Endpoints.INSTANCE.batchCount = options['batch-count']
|
53
55
|
Endpoints.INSTANCE.chainQueryAPI = options['chainquery-server']
|
54
56
|
Endpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']
|
55
57
|
|
package/src/service.ts
CHANGED
@@ -5,6 +5,7 @@ import { withAbort } from 'ix/Ix.dom.asynciterable.operators.js'
|
|
5
5
|
|
6
6
|
import {
|
7
7
|
DataBinding,
|
8
|
+
DeepPartial,
|
8
9
|
Empty,
|
9
10
|
HandlerType,
|
10
11
|
ProcessBindingResponse,
|
@@ -14,6 +15,7 @@ import {
|
|
14
15
|
ProcessorServiceImplementation,
|
15
16
|
ProcessResult,
|
16
17
|
ProcessStreamRequest,
|
18
|
+
ProcessStreamResponse,
|
17
19
|
StartRequest
|
18
20
|
} from '@sentio/protos'
|
19
21
|
|
@@ -22,6 +24,8 @@ import { errorString, mergeProcessResults } from './utils.js'
|
|
22
24
|
import { freezeGlobalConfig, GLOBAL_CONFIG } from './global-config.js'
|
23
25
|
|
24
26
|
import { StoreContext } from './db-context.js'
|
27
|
+
import { Subject } from 'rxjs'
|
28
|
+
|
25
29
|
;(BigInt.prototype as any).toJSON = function () {
|
26
30
|
return this.toString()
|
27
31
|
}
|
@@ -162,38 +166,50 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
162
166
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
163
167
|
}
|
164
168
|
|
165
|
-
const
|
166
|
-
|
167
|
-
for await (const request of requests) {
|
168
|
-
if (request.binding) {
|
169
|
-
const binding = request.binding
|
170
|
-
PluginManager.INSTANCE.processBinding(binding, dbContext)
|
171
|
-
.then((result) => {
|
172
|
-
dbContext.subject.next({
|
173
|
-
result,
|
174
|
-
processId: request.processId
|
175
|
-
})
|
176
|
-
// dbContext.subject.complete()
|
177
|
-
recordRuntimeInfo(result, binding.handlerType)
|
178
|
-
})
|
179
|
-
.catch((e) => {
|
180
|
-
dbContext.error(request.processId, e)
|
181
|
-
})
|
182
|
-
}
|
183
|
-
if (request.dbResult) {
|
184
|
-
dbContext.result(request.dbResult)
|
185
|
-
}
|
186
|
-
}
|
187
|
-
resolve(null)
|
188
|
-
})
|
169
|
+
const subject = new Subject<DeepPartial<ProcessStreamResponse>>()
|
170
|
+
this.handleRequests(requests, subject)
|
189
171
|
.then(() => {
|
190
|
-
|
172
|
+
subject.complete()
|
191
173
|
})
|
192
174
|
.catch((e) => {
|
193
|
-
|
194
|
-
|
175
|
+
console.error(e)
|
176
|
+
subject.error(e)
|
195
177
|
})
|
196
|
-
yield* from(
|
178
|
+
yield* from(subject).pipe(withAbort(context.signal))
|
179
|
+
}
|
180
|
+
|
181
|
+
private async handleRequests(
|
182
|
+
requests: AsyncIterable<ProcessStreamRequest>,
|
183
|
+
subject: Subject<DeepPartial<ProcessStreamResponse>>
|
184
|
+
) {
|
185
|
+
const contexts: Record<number, StoreContext> = {}
|
186
|
+
|
187
|
+
for await (const request of requests) {
|
188
|
+
if (request.binding) {
|
189
|
+
const binding = request.binding
|
190
|
+
const dbContext = new StoreContext(subject, request.processId)
|
191
|
+
contexts[request.processId] = dbContext
|
192
|
+
PluginManager.INSTANCE.processBinding(binding, dbContext)
|
193
|
+
.then((result) => {
|
194
|
+
subject.next({
|
195
|
+
result,
|
196
|
+
processId: request.processId
|
197
|
+
})
|
198
|
+
recordRuntimeInfo(result, binding.handlerType)
|
199
|
+
})
|
200
|
+
.catch((e) => {
|
201
|
+
console.error(e)
|
202
|
+
dbContext.error(request.processId, e)
|
203
|
+
})
|
204
|
+
.finally(() => {
|
205
|
+
delete contexts[request.processId]
|
206
|
+
})
|
207
|
+
}
|
208
|
+
if (request.dbResult) {
|
209
|
+
const dbContext = contexts[request.processId]
|
210
|
+
dbContext?.result(request.dbResult)
|
211
|
+
}
|
212
|
+
}
|
197
213
|
}
|
198
214
|
}
|
199
215
|
|