@sentio/runtime 2.59.0-rc.3 → 2.59.0-rc.30

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/src/service.ts CHANGED
@@ -56,6 +56,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
56
56
  private readonly enablePreprocess: boolean
57
57
 
58
58
  private preparedData: PreparedData | undefined
59
+ readonly enablePartition: boolean
59
60
 
60
61
  constructor(loader: () => Promise<any>, shutdownHandler?: () => void) {
61
62
  this.loader = loader
@@ -64,6 +65,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
64
65
  this.enablePreprocess = process.env['ENABLE_PREPROCESS']
65
66
  ? process.env['ENABLE_PREPROCESS'].toLowerCase() == 'true'
66
67
  : false
68
+
69
+ this.enablePartition = process.env['SENTIO_ENABLE_BINDING_DATA_PARTITION'] == 'true'
67
70
  }
68
71
 
69
72
  async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {
@@ -418,9 +421,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
418
421
  subject: Subject<DeepPartial<ProcessStreamResponse>>
419
422
  ) {
420
423
  const contexts = new Contexts()
424
+ let lastBinding: DataBinding | undefined = undefined
421
425
  for await (const request of requests) {
422
426
  try {
423
- // console.debug('received request:', request)
427
+ // console.log('received request:', request, 'lastBinding:', lastBinding)
424
428
  if (request.binding) {
425
429
  process_binding_count.add(1)
426
430
 
@@ -433,31 +437,29 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
433
437
  })
434
438
  continue
435
439
  }
440
+ lastBinding = request.binding
436
441
 
437
- const binding = request.binding
438
- const dbContext = contexts.new(request.processId, subject)
439
- const start = Date.now()
440
- PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext)
441
- .then(async (result) => {
442
- // await all pending db requests
443
- await dbContext.awaitPendings()
442
+ if (this.enablePartition) {
443
+ PluginManager.INSTANCE.partition(request.binding).then((partitions) => {
444
444
  subject.next({
445
- result,
446
- processId: request.processId
445
+ processId: request.processId,
446
+ partitions
447
447
  })
448
- recordRuntimeInfo(result, binding.handlerType)
449
- })
450
- .catch((e) => {
451
- console.debug(e)
452
- dbContext.error(request.processId, e)
453
- process_binding_error.add(1)
454
- })
455
- .finally(() => {
456
- const cost = Date.now() - start
457
- process_binding_time.add(cost)
458
- contexts.delete(request.processId)
459
448
  })
449
+ } else {
450
+ this.startProcess(request.processId, request.binding, contexts, subject)
451
+ }
452
+ }
453
+
454
+ if (request.start) {
455
+ if (!lastBinding) {
456
+ console.error('start request received without binding')
457
+ subject.error(new Error('start request received without binding'))
458
+ continue
459
+ }
460
+ this.startProcess(request.processId, lastBinding, contexts, subject)
460
461
  }
462
+
461
463
  if (request.dbResult) {
462
464
  const dbContext = contexts.get(request.processId)
463
465
  try {
@@ -472,6 +474,36 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
472
474
  }
473
475
  }
474
476
  }
477
+
478
+ private startProcess(
479
+ processId: number,
480
+ binding: DataBinding,
481
+ contexts: Contexts,
482
+ subject: Subject<DeepPartial<ProcessStreamResponse>>
483
+ ) {
484
+ const dbContext = contexts.new(processId, subject)
485
+ const start = Date.now()
486
+ PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext)
487
+ .then(async (result) => {
488
+ // await all pending db requests
489
+ await dbContext.awaitPendings()
490
+ subject.next({
491
+ result,
492
+ processId: processId
493
+ })
494
+ recordRuntimeInfo(result, binding.handlerType)
495
+ })
496
+ .catch((e) => {
497
+ console.error(e)
498
+ dbContext.error(processId, e)
499
+ process_binding_error.add(1)
500
+ })
501
+ .finally(() => {
502
+ const cost = Date.now() - start
503
+ process_binding_time.add(cost)
504
+ contexts.delete(processId)
505
+ })
506
+ }
475
507
  }
476
508
 
477
509
  export function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
package/src/utils.ts CHANGED
@@ -16,6 +16,7 @@ export function mergeProcessResults(results: ProcessResult[]): Required<ProcessR
16
16
  res.gauges = res.gauges.concat(r.gauges)
17
17
  res.events = res.events.concat(r.events)
18
18
  res.exports = res.exports.concat(r.exports)
19
+ res.timeseriesResult = res.timeseriesResult.concat(r.timeseriesResult)
19
20
  res.states = {
20
21
  configUpdated: res.states?.configUpdated || r.states?.configUpdated || false
21
22
  }