@sentio/runtime 2.40.0-rc.30 → 2.40.0-rc.32

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.
@@ -59708,6 +59708,7 @@ var {
59708
59708
  } = dbMetrics;
59709
59709
  var STORE_BATCH_IDLE = process2.env["STORE_BATCH_MAX_IDLE"] ? parseInt(process2.env["STORE_BATCH_MAX_IDLE"]) : 1;
59710
59710
  var STORE_BATCH_SIZE = process2.env["STORE_BATCH_SIZE"] ? parseInt(process2.env["STORE_BATCH_SIZE"]) : 10;
59711
+ var STORE_UPSERT_NO_WAIT = process2.env["STORE_UPSERT_NO_WAIT"] === "true";
59711
59712
  var timeoutError = new Error("timeout");
59712
59713
  var _StoreContext = class {
59713
59714
  constructor(subject, processId) {
@@ -59744,6 +59745,11 @@ var _StoreContext = class {
59744
59745
  processId: this.processId
59745
59746
  });
59746
59747
  send_counts[requestType]?.add(1);
59748
+ if (requestType === "upsert" && STORE_UPSERT_NO_WAIT) {
59749
+ return Promise.resolve({
59750
+ opId
59751
+ });
59752
+ }
59747
59753
  return Promise.race(promises).then((result) => {
59748
59754
  if (timeoutSecs) {
59749
59755
  console.debug("db request", requestType, "op", opId, " took", Date.now() - start, "ms");
@@ -59770,6 +59776,10 @@ var _StoreContext = class {
59770
59776
  recv_counts[defer.requestType]?.add(1);
59771
59777
  }
59772
59778
  if (dbResult.error) {
59779
+ if (defer.requestType == "upsert" && STORE_UPSERT_NO_WAIT) {
59780
+ console.error("upsert no_wait enabled, the error may not be thrown in user function", dbResult.error);
59781
+ throw new Error(dbResult.error);
59782
+ }
59773
59783
  defer.reject(new Error(dbResult.error));
59774
59784
  } else {
59775
59785
  defer.resolve(dbResult);
@@ -59809,19 +59819,32 @@ var _StoreContext = class {
59809
59819
  if (request.entity.length >= STORE_BATCH_SIZE) {
59810
59820
  this.sendBatch();
59811
59821
  }
59822
+ if (STORE_UPSERT_NO_WAIT) {
59823
+ return {
59824
+ opId: this.upsertBatch.opId
59825
+ };
59826
+ }
59812
59827
  return promise;
59813
59828
  } else {
59814
59829
  const opId = _StoreContext.opCounter++;
59815
- const promise = this.newPromise(opId, "upsert");
59816
59830
  const timeout = setTimeout(() => {
59817
59831
  this.sendBatch();
59818
59832
  }, STORE_BATCH_IDLE);
59833
+ const start = Date.now();
59834
+ const promise = this.newPromise(opId, "upsert").finally(() => {
59835
+ request_times["upsert"].add(Date.now() - start);
59836
+ });
59819
59837
  this.upsertBatch = {
59820
59838
  opId,
59821
59839
  request: req,
59822
59840
  promise,
59823
59841
  timer: timeout
59824
59842
  };
59843
+ if (STORE_UPSERT_NO_WAIT) {
59844
+ return {
59845
+ opId: this.upsertBatch.opId
59846
+ };
59847
+ }
59825
59848
  return promise;
59826
59849
  }
59827
59850
  }
@@ -80405,7 +80428,11 @@ var ProcessorServiceImpl = class {
80405
80428
  }
80406
80429
  if (request.dbResult) {
80407
80430
  const dbContext = contexts.get(request.processId);
80408
- dbContext?.result(request.dbResult);
80431
+ try {
80432
+ dbContext?.result(request.dbResult);
80433
+ } catch (e) {
80434
+ subject.error(new Error("db result error, process should stop"));
80435
+ }
80409
80436
  }
80410
80437
  } catch (e) {
80411
80438
  console.error("unexpect error during handle loop", e);
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  makeEthCallKey,
15
15
  mergeProcessResults,
16
16
  timeoutError
17
- } from "./chunk-XWTAA3QK.js";
17
+ } from "./chunk-KVYXDEGV.js";
18
18
 
19
19
  // src/state.ts
20
20
  var _State = class {
@@ -41,7 +41,7 @@ import {
41
41
  require_minimal,
42
42
  require_src,
43
43
  trace
44
- } from "./chunk-XWTAA3QK.js";
44
+ } from "./chunk-KVYXDEGV.js";
45
45
 
46
46
  // ../../node_modules/.pnpm/universalify@2.0.1/node_modules/universalify/index.js
47
47
  var require_universalify = __commonJS({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.40.0-rc.30",
3
+ "version": "2.40.0-rc.32",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
package/src/db-context.ts CHANGED
@@ -20,6 +20,7 @@ const {
20
20
  } = dbMetrics
21
21
  const STORE_BATCH_IDLE = process.env['STORE_BATCH_MAX_IDLE'] ? parseInt(process.env['STORE_BATCH_MAX_IDLE']) : 1
22
22
  const STORE_BATCH_SIZE = process.env['STORE_BATCH_SIZE'] ? parseInt(process.env['STORE_BATCH_SIZE']) : 10
23
+ const STORE_UPSERT_NO_WAIT = process.env['STORE_UPSERT_NO_WAIT'] === 'true'
23
24
 
24
25
  type Request = Omit<DBRequest, 'opId'>
25
26
  type RequestType = keyof Request
@@ -76,6 +77,13 @@ export class StoreContext {
76
77
 
77
78
  send_counts[requestType]?.add(1)
78
79
 
80
+ if (requestType === 'upsert' && STORE_UPSERT_NO_WAIT) {
81
+
82
+ return Promise.resolve({
83
+ opId,
84
+ } as DBResponse)
85
+ }
86
+
79
87
  return Promise.race(promises)
80
88
  .then((result: DBResponse) => {
81
89
  if (timeoutSecs) {
@@ -107,6 +115,11 @@ export class StoreContext {
107
115
  recv_counts[defer.requestType]?.add(1)
108
116
  }
109
117
  if (dbResult.error) {
118
+ if (defer.requestType == 'upsert' && STORE_UPSERT_NO_WAIT) {
119
+ console.error('upsert no_wait enabled, the error may not be thrown in user function', dbResult.error)
120
+ throw new Error(dbResult.error)
121
+ }
122
+
110
123
  defer.reject(new Error(dbResult.error))
111
124
  } else {
112
125
  defer.resolve(dbResult)
@@ -159,19 +172,34 @@ export class StoreContext {
159
172
  if (request.entity.length >= STORE_BATCH_SIZE) {
160
173
  this.sendBatch()
161
174
  }
175
+ if (STORE_UPSERT_NO_WAIT) {
176
+ return {
177
+ opId: this.upsertBatch.opId
178
+ }
179
+ }
180
+
162
181
  return promise
163
182
  } else {
164
183
  const opId = StoreContext.opCounter++
165
- const promise = this.newPromise<DBResponse>(opId, 'upsert')
166
184
  const timeout = setTimeout(() => {
167
185
  this.sendBatch()
168
186
  }, STORE_BATCH_IDLE)
187
+ const start = Date.now()
188
+ const promise = this.newPromise<DBResponse>(opId, 'upsert').finally(() => {
189
+ request_times['upsert'].add(Date.now() - start)
190
+ })
169
191
 
170
192
  this.upsertBatch = {
171
193
  opId,
172
194
  request: req,
173
195
  promise,
174
- timer: timeout
196
+ timer: timeout,
197
+ }
198
+
199
+ if (STORE_UPSERT_NO_WAIT) {
200
+ return {
201
+ opId: this.upsertBatch.opId
202
+ }
175
203
  }
176
204
 
177
205
  return promise
package/src/service.ts CHANGED
@@ -433,7 +433,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
433
433
  }
434
434
  if (request.dbResult) {
435
435
  const dbContext = contexts.get(request.processId)
436
- dbContext?.result(request.dbResult)
436
+ try {
437
+ dbContext?.result(request.dbResult)
438
+ } catch (e) {
439
+ subject.error(new Error("db result error, process should stop"))
440
+ }
437
441
  }
438
442
  } catch (e) {
439
443
  // should not happen