@dbos-inc/dbos-sdk 2.10.19-preview → 2.10.20-preview
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.
@@ -1,5 +1,6 @@
|
|
1
|
+
/// <reference types="node" />
|
1
2
|
import { DBOSConfigInternal } from './dbos-executor';
|
2
|
-
import { Pool,
|
3
|
+
import { Pool, PoolConfig, Client } from 'pg';
|
3
4
|
import { GetPendingWorkflowsOutput, GetQueuedWorkflowsInput, GetWorkflowsInput, StatusString } from './workflow';
|
4
5
|
import { operation_outputs } from '../schemas/system_db_schema';
|
5
6
|
import { HTTPRequest } from './context';
|
@@ -132,7 +133,7 @@ export declare class PostgresSystemDatabase implements SystemDatabase {
|
|
132
133
|
readonly pool: Pool;
|
133
134
|
readonly systemPoolConfig: PoolConfig;
|
134
135
|
readonly knexDB: Knex;
|
135
|
-
notificationsClient:
|
136
|
+
notificationsClient: Client | null;
|
136
137
|
dbPollingIntervalResultMs: number;
|
137
138
|
dbPollingIntervalEventMs: number;
|
138
139
|
shouldUseDBNotifications: boolean;
|
@@ -168,13 +169,13 @@ export declare class PostgresSystemDatabase implements SystemDatabase {
|
|
168
169
|
readonly nullTopic = "__null__topic__";
|
169
170
|
send(workflowID: string, functionID: number, destinationID: string, message: string | null, topic?: string): Promise<void>;
|
170
171
|
recv(workflowID: string, functionID: number, timeoutFunctionID: number, topic?: string, timeoutSeconds?: number): Promise<string | null>;
|
172
|
+
setWorkflowStatus(workflowID: string, status: (typeof StatusString)[keyof typeof StatusString], resetRecoveryAttempts: boolean): Promise<void>;
|
171
173
|
setEvent(workflowID: string, functionID: number, key: string, message: string | null): Promise<void>;
|
172
174
|
getEvent(workflowID: string, key: string, timeoutSeconds: number, callerWorkflow?: {
|
173
175
|
workflowID: string;
|
174
176
|
functionID: number;
|
175
177
|
timeoutFunctionID: number;
|
176
178
|
}): Promise<string | null>;
|
177
|
-
setWorkflowStatus(workflowID: string, status: (typeof StatusString)[keyof typeof StatusString], resetRecoveryAttempts: boolean): Promise<void>;
|
178
179
|
cancelWorkflow(workflowID: string): Promise<void>;
|
179
180
|
checkIfCanceled(workflowID: string): Promise<void>;
|
180
181
|
resumeWorkflow(workflowID: string): Promise<void>;
|
@@ -182,6 +183,11 @@ export declare class PostgresSystemDatabase implements SystemDatabase {
|
|
182
183
|
awaitRunningWorkflows(): Promise<void>;
|
183
184
|
getWorkflowStatus(workflowID: string, callerID?: string, callerFN?: number): Promise<WorkflowStatusInternal | null>;
|
184
185
|
awaitWorkflowResult(workflowID: string, timeoutSeconds?: number, callerID?: string, timerFuncID?: number): Promise<SystemDatabaseStoredResult | undefined>;
|
186
|
+
/**
|
187
|
+
* A background process that listens for notifications from Postgres then signals the appropriate
|
188
|
+
* workflow listener by resolving its promise.
|
189
|
+
*/
|
190
|
+
reconnectTimeout: NodeJS.Timeout | null;
|
185
191
|
getEventDispatchState(service: string, workflowName: string, key: string): Promise<DBOSEventReceiverState | undefined>;
|
186
192
|
upsertEventDispatchState(state: DBOSEventReceiverState): Promise<DBOSEventReceiverState>;
|
187
193
|
listWorkflows(input: GetWorkflowsInput): Promise<WorkflowStatusInternal[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"system_database.d.ts","sourceRoot":"","sources":["../../src/system_database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAiB,IAAI,
|
1
|
+
{"version":3,"file":"system_database.d.ts","sourceRoot":"","sources":["../../src/system_database.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAiB,IAAI,EAA4B,UAAU,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAUvF,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACjH,OAAO,EAEL,iBAAiB,EAIlB,M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AAE,MAAM,EAClB,cAAc,CAAC,EAAE,MAAM,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAAC;IA+ElD;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAQ;IAmDzC,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAuBxC,wBAAwB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA8BxF,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;IA0C1E,mBAAmB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAmCtF,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAY1D,6BAA6B,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAoHrH"}
|
@@ -1,4 +1,13 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
|
+
};
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
13
|
};
|
@@ -233,6 +242,83 @@ function mapWorkflowStatus(row) {
|
|
233
242
|
priority: row.priority ?? 0,
|
234
243
|
};
|
235
244
|
}
|
245
|
+
function retriablePostgresException(e) {
|
246
|
+
// Recurse into AggregateErrors of various types
|
247
|
+
if (e && typeof e === 'object' && 'errors' in e && Array.isArray(e.errors)) {
|
248
|
+
return e.errors.some((error) => retriablePostgresException(error));
|
249
|
+
}
|
250
|
+
// For Postgres errors, check the code
|
251
|
+
if (e instanceof pg_1.DatabaseError && e.code) {
|
252
|
+
// Operator intervention
|
253
|
+
if (e.code.startsWith('57')) {
|
254
|
+
return true;
|
255
|
+
}
|
256
|
+
// Insufficent resources
|
257
|
+
if (e.code.startsWith('53')) {
|
258
|
+
return true;
|
259
|
+
}
|
260
|
+
// Connection exception
|
261
|
+
if (e.code.startsWith('08')) {
|
262
|
+
return true;
|
263
|
+
}
|
264
|
+
}
|
265
|
+
// Otherwise, check for network issues in the string
|
266
|
+
const errorString = e instanceof Error ? e.stack || e.message : String(e);
|
267
|
+
if (errorString.includes('ECONNREFUSED')) {
|
268
|
+
return true;
|
269
|
+
}
|
270
|
+
if (errorString.includes('ECONNRESET')) {
|
271
|
+
return true;
|
272
|
+
}
|
273
|
+
if (errorString.toLowerCase().includes('connection timeout')) {
|
274
|
+
return true;
|
275
|
+
}
|
276
|
+
if (errorString.toLowerCase().includes('connection terminated unexpectedly')) {
|
277
|
+
return true;
|
278
|
+
}
|
279
|
+
if (errorString.toLowerCase().includes('client has encountered a connection error')) {
|
280
|
+
return true;
|
281
|
+
}
|
282
|
+
return false;
|
283
|
+
}
|
284
|
+
/**
|
285
|
+
* If a workflow encounters a database connection issue while performing an operation,
|
286
|
+
* block the workflow and retry the operation until it reconnects and succeeds.
|
287
|
+
* In other words, if DBOS loses its database connection, everything pauses until the connection is recovered,
|
288
|
+
* trading off availability for correctness.
|
289
|
+
*/
|
290
|
+
function dbRetry(options = {}) {
|
291
|
+
const { initialBackoff = 1.0, maxBackoff = 60.0 } = options;
|
292
|
+
return function (target, propertyName, descriptor) {
|
293
|
+
const method = descriptor.value;
|
294
|
+
descriptor.value = async function (...args) {
|
295
|
+
let retries = 0;
|
296
|
+
let backoff = initialBackoff;
|
297
|
+
while (true) {
|
298
|
+
try {
|
299
|
+
return await method.apply(this, args);
|
300
|
+
}
|
301
|
+
catch (e) {
|
302
|
+
if (retriablePostgresException(e)) {
|
303
|
+
retries++;
|
304
|
+
// Calculate backoff with jitter
|
305
|
+
const actualBackoff = backoff * (0.5 + Math.random());
|
306
|
+
dbos_executor_1.DBOSExecutor.globalInstance?.logger.warn(`Database connection failed: ${e instanceof Error ? e.message : String(e)}. ` +
|
307
|
+
`Retrying in ${actualBackoff.toFixed(2)}s (attempt ${retries})`);
|
308
|
+
// Sleep with backoff
|
309
|
+
await (0, utils_1.sleepms)(actualBackoff * 1000); // Convert to milliseconds
|
310
|
+
// Increase backoff for next attempt (exponential)
|
311
|
+
backoff = Math.min(backoff * 2, maxBackoff);
|
312
|
+
}
|
313
|
+
else {
|
314
|
+
throw e;
|
315
|
+
}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
};
|
319
|
+
return descriptor;
|
320
|
+
};
|
321
|
+
}
|
236
322
|
class PostgresSystemDatabase {
|
237
323
|
pgPoolConfig;
|
238
324
|
systemDatabaseName;
|
@@ -284,6 +370,14 @@ class PostgresSystemDatabase {
|
|
284
370
|
application_name: `dbos_transact_${utils_1.globalParams.executorID}_${utils_1.globalParams.appVersion}`,
|
285
371
|
};
|
286
372
|
this.pool = new pg_1.Pool(this.systemPoolConfig);
|
373
|
+
this.pool.on('error', (err) => {
|
374
|
+
this.logger.warn(`Unexpected error in pool: ${err}`);
|
375
|
+
});
|
376
|
+
this.pool.on('connect', (client) => {
|
377
|
+
client.on('error', (err) => {
|
378
|
+
this.logger.warn(`Unexpected error in idle client: ${err}`);
|
379
|
+
});
|
380
|
+
});
|
287
381
|
const knexConfig = {
|
288
382
|
client: 'pg',
|
289
383
|
connection: this.systemPoolConfig,
|
@@ -324,9 +418,17 @@ class PostgresSystemDatabase {
|
|
324
418
|
}
|
325
419
|
async destroy() {
|
326
420
|
await this.knexDB.destroy();
|
421
|
+
if (this.reconnectTimeout) {
|
422
|
+
clearTimeout(this.reconnectTimeout);
|
423
|
+
}
|
327
424
|
if (this.notificationsClient) {
|
328
|
-
|
329
|
-
|
425
|
+
try {
|
426
|
+
this.notificationsClient.removeAllListeners();
|
427
|
+
await this.notificationsClient.end();
|
428
|
+
}
|
429
|
+
catch (e) {
|
430
|
+
this.logger.warn(`Error ending notifications client: ${String(e)}`);
|
431
|
+
}
|
330
432
|
}
|
331
433
|
await this.pool.end();
|
332
434
|
}
|
@@ -381,8 +483,12 @@ class PostgresSystemDatabase {
|
|
381
483
|
return { status, deadlineEpochMS };
|
382
484
|
}
|
383
485
|
finally {
|
384
|
-
|
385
|
-
|
486
|
+
try {
|
487
|
+
await client.query('COMMIT');
|
488
|
+
}
|
489
|
+
finally {
|
490
|
+
client.release();
|
491
|
+
}
|
386
492
|
}
|
387
493
|
}
|
388
494
|
async recordWorkflowOutput(workflowID, status) {
|
@@ -577,8 +683,8 @@ class PostgresSystemDatabase {
|
|
577
683
|
async send(workflowID, functionID, destinationID, message, topic) {
|
578
684
|
topic = topic ?? this.nullTopic;
|
579
685
|
const client = await this.pool.connect();
|
580
|
-
await client.query('BEGIN ISOLATION LEVEL READ COMMITTED');
|
581
686
|
try {
|
687
|
+
await client.query('BEGIN ISOLATION LEVEL READ COMMITTED');
|
582
688
|
await this.#runAndRecordResult(client, exports.DBOS_FUNCNAME_SEND, workflowID, functionID, async () => {
|
583
689
|
await client.query(`INSERT INTO ${dbos_executor_1.DBOSExecutor.systemDBSchemaName}.notifications (destination_uuid, topic, message) VALUES ($1, $2, $3);`, [destinationID, topic, message]);
|
584
690
|
await client.query('COMMIT');
|
@@ -696,6 +802,16 @@ class PostgresSystemDatabase {
|
|
696
802
|
}
|
697
803
|
return message;
|
698
804
|
}
|
805
|
+
// Only used in tests
|
806
|
+
async setWorkflowStatus(workflowID, status, resetRecoveryAttempts) {
|
807
|
+
const client = await this.pool.connect();
|
808
|
+
try {
|
809
|
+
await updateWorkflowStatus(client, workflowID, status, { update: { resetRecoveryAttempts } });
|
810
|
+
}
|
811
|
+
finally {
|
812
|
+
client.release();
|
813
|
+
}
|
814
|
+
}
|
699
815
|
async setEvent(workflowID, functionID, key, message) {
|
700
816
|
const client = await this.pool.connect();
|
701
817
|
try {
|
@@ -797,15 +913,6 @@ class PostgresSystemDatabase {
|
|
797
913
|
}
|
798
914
|
return value;
|
799
915
|
}
|
800
|
-
async setWorkflowStatus(workflowID, status, resetRecoveryAttempts) {
|
801
|
-
const client = await this.pool.connect();
|
802
|
-
try {
|
803
|
-
await updateWorkflowStatus(client, workflowID, status, { update: { resetRecoveryAttempts } });
|
804
|
-
}
|
805
|
-
finally {
|
806
|
-
client.release();
|
807
|
-
}
|
808
|
-
}
|
809
916
|
#setWFCancelMap(workflowID) {
|
810
917
|
if (this.runningWorkflowMap.has(workflowID)) {
|
811
918
|
this.workflowCancellationMap.set(workflowID, true);
|
@@ -1035,25 +1142,51 @@ class PostgresSystemDatabase {
|
|
1035
1142
|
* A background process that listens for notifications from Postgres then signals the appropriate
|
1036
1143
|
* workflow listener by resolving its promise.
|
1037
1144
|
*/
|
1145
|
+
reconnectTimeout = null;
|
1038
1146
|
async #listenForNotifications() {
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
if (!this.shouldUseDBNotifications)
|
1044
|
-
return; // Testing parameter
|
1045
|
-
if (msg.channel === 'dbos_notifications_channel') {
|
1046
|
-
if (msg.payload) {
|
1047
|
-
this.notificationsMap.callCallbacks(msg.payload);
|
1147
|
+
const connect = async () => {
|
1148
|
+
const reconnect = () => {
|
1149
|
+
if (this.reconnectTimeout) {
|
1150
|
+
return;
|
1048
1151
|
}
|
1152
|
+
this.reconnectTimeout = setTimeout(async () => {
|
1153
|
+
this.reconnectTimeout = null;
|
1154
|
+
await connect();
|
1155
|
+
}, 1000);
|
1156
|
+
};
|
1157
|
+
let client = null;
|
1158
|
+
try {
|
1159
|
+
client = new pg_1.Client(this.systemPoolConfig);
|
1160
|
+
await client.connect();
|
1161
|
+
await client.query('LISTEN dbos_notifications_channel;');
|
1162
|
+
await client.query('LISTEN dbos_workflow_events_channel;');
|
1163
|
+
const handler = (msg) => {
|
1164
|
+
if (!this.shouldUseDBNotifications)
|
1165
|
+
return;
|
1166
|
+
if (msg.channel === 'dbos_notifications_channel' && msg.payload) {
|
1167
|
+
this.notificationsMap.callCallbacks(msg.payload);
|
1168
|
+
}
|
1169
|
+
else if (msg.channel === 'dbos_workflow_events_channel' && msg.payload) {
|
1170
|
+
this.workflowEventsMap.callCallbacks(msg.payload);
|
1171
|
+
}
|
1172
|
+
};
|
1173
|
+
client.on('notification', handler);
|
1174
|
+
client.on('error', async (err) => {
|
1175
|
+
this.logger.warn(`Error in notifications client: ${err}`);
|
1176
|
+
client.removeAllListeners();
|
1177
|
+
await client.end();
|
1178
|
+
reconnect();
|
1179
|
+
});
|
1180
|
+
this.notificationsClient = client;
|
1049
1181
|
}
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1182
|
+
catch (error) {
|
1183
|
+
this.logger.warn(`Error in notifications listener: ${String(error)}`);
|
1184
|
+
client.removeAllListeners();
|
1185
|
+
await client.end();
|
1186
|
+
reconnect();
|
1054
1187
|
}
|
1055
1188
|
};
|
1056
|
-
|
1189
|
+
await connect();
|
1057
1190
|
}
|
1058
1191
|
// Event dispatcher queries / updates
|
1059
1192
|
async getEventDispatchState(service, workflowName, key) {
|
@@ -1272,4 +1405,94 @@ class PostgresSystemDatabase {
|
|
1272
1405
|
}
|
1273
1406
|
}
|
1274
1407
|
exports.PostgresSystemDatabase = PostgresSystemDatabase;
|
1408
|
+
__decorate([
|
1409
|
+
dbRetry(),
|
1410
|
+
__metadata("design:type", Function),
|
1411
|
+
__metadata("design:paramtypes", [Object, Number]),
|
1412
|
+
__metadata("design:returntype", Promise)
|
1413
|
+
], PostgresSystemDatabase.prototype, "initWorkflowStatus", null);
|
1414
|
+
__decorate([
|
1415
|
+
dbRetry(),
|
1416
|
+
__metadata("design:type", Function),
|
1417
|
+
__metadata("design:paramtypes", [String, Object]),
|
1418
|
+
__metadata("design:returntype", Promise)
|
1419
|
+
], PostgresSystemDatabase.prototype, "recordWorkflowOutput", null);
|
1420
|
+
__decorate([
|
1421
|
+
dbRetry(),
|
1422
|
+
__metadata("design:type", Function),
|
1423
|
+
__metadata("design:paramtypes", [String, Object]),
|
1424
|
+
__metadata("design:returntype", Promise)
|
1425
|
+
], PostgresSystemDatabase.prototype, "recordWorkflowError", null);
|
1426
|
+
__decorate([
|
1427
|
+
dbRetry(),
|
1428
|
+
__metadata("design:type", Function),
|
1429
|
+
__metadata("design:paramtypes", [String, Number]),
|
1430
|
+
__metadata("design:returntype", Promise)
|
1431
|
+
], PostgresSystemDatabase.prototype, "getOperationResultAndThrowIfCancelled", null);
|
1432
|
+
__decorate([
|
1433
|
+
dbRetry(),
|
1434
|
+
__metadata("design:type", Function),
|
1435
|
+
__metadata("design:paramtypes", [String, Number, String, Boolean, Object]),
|
1436
|
+
__metadata("design:returntype", Promise)
|
1437
|
+
], PostgresSystemDatabase.prototype, "recordOperationResult", null);
|
1438
|
+
__decorate([
|
1439
|
+
dbRetry(),
|
1440
|
+
__metadata("design:type", Function),
|
1441
|
+
__metadata("design:paramtypes", [String, Number, Number]),
|
1442
|
+
__metadata("design:returntype", Promise)
|
1443
|
+
], PostgresSystemDatabase.prototype, "durableSleepms", null);
|
1444
|
+
__decorate([
|
1445
|
+
dbRetry(),
|
1446
|
+
__metadata("design:type", Function),
|
1447
|
+
__metadata("design:paramtypes", [String, Number, String, Object, String]),
|
1448
|
+
__metadata("design:returntype", Promise)
|
1449
|
+
], PostgresSystemDatabase.prototype, "send", null);
|
1450
|
+
__decorate([
|
1451
|
+
dbRetry(),
|
1452
|
+
__metadata("design:type", Function),
|
1453
|
+
__metadata("design:paramtypes", [String, Number, Number, String, Number]),
|
1454
|
+
__metadata("design:returntype", Promise)
|
1455
|
+
], PostgresSystemDatabase.prototype, "recv", null);
|
1456
|
+
__decorate([
|
1457
|
+
dbRetry(),
|
1458
|
+
__metadata("design:type", Function),
|
1459
|
+
__metadata("design:paramtypes", [String, Number, String, Object]),
|
1460
|
+
__metadata("design:returntype", Promise)
|
1461
|
+
], PostgresSystemDatabase.prototype, "setEvent", null);
|
1462
|
+
__decorate([
|
1463
|
+
dbRetry(),
|
1464
|
+
__metadata("design:type", Function),
|
1465
|
+
__metadata("design:paramtypes", [String, String, Number, Object]),
|
1466
|
+
__metadata("design:returntype", Promise)
|
1467
|
+
], PostgresSystemDatabase.prototype, "getEvent", null);
|
1468
|
+
__decorate([
|
1469
|
+
dbRetry(),
|
1470
|
+
__metadata("design:type", Function),
|
1471
|
+
__metadata("design:paramtypes", [String]),
|
1472
|
+
__metadata("design:returntype", Promise)
|
1473
|
+
], PostgresSystemDatabase.prototype, "checkIfCanceled", null);
|
1474
|
+
__decorate([
|
1475
|
+
dbRetry(),
|
1476
|
+
__metadata("design:type", Function),
|
1477
|
+
__metadata("design:paramtypes", [String, String, Number]),
|
1478
|
+
__metadata("design:returntype", Promise)
|
1479
|
+
], PostgresSystemDatabase.prototype, "getWorkflowStatus", null);
|
1480
|
+
__decorate([
|
1481
|
+
dbRetry(),
|
1482
|
+
__metadata("design:type", Function),
|
1483
|
+
__metadata("design:paramtypes", [String, Number, String, Number]),
|
1484
|
+
__metadata("design:returntype", Promise)
|
1485
|
+
], PostgresSystemDatabase.prototype, "awaitWorkflowResult", null);
|
1486
|
+
__decorate([
|
1487
|
+
dbRetry(),
|
1488
|
+
__metadata("design:type", Function),
|
1489
|
+
__metadata("design:paramtypes", [String, String, String]),
|
1490
|
+
__metadata("design:returntype", Promise)
|
1491
|
+
], PostgresSystemDatabase.prototype, "getEventDispatchState", null);
|
1492
|
+
__decorate([
|
1493
|
+
dbRetry(),
|
1494
|
+
__metadata("design:type", Function),
|
1495
|
+
__metadata("design:paramtypes", [Object]),
|
1496
|
+
__metadata("design:returntype", Promise)
|
1497
|
+
], PostgresSystemDatabase.prototype, "upsertEventDispatchState", null);
|
1275
1498
|
//# sourceMappingURL=system_database.js.map
|