@dbos-inc/dbos-sdk 2.10.3-preview → 2.10.6-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.
- package/dist/src/context.d.ts +1 -1
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +28 -23
- package/dist/src/dbos-executor.js.map +1 -1
- package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
- package/dist/src/dbos-runtime/runtime.js +1 -2
- package/dist/src/dbos-runtime/runtime.js.map +1 -1
- package/dist/src/dbos.d.ts +5 -11
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +119 -102
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/error.d.ts +1 -1
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +4 -4
- package/dist/src/error.js.map +1 -1
- package/dist/src/httpServer/middleware.js +5 -5
- package/dist/src/httpServer/middleware.js.map +1 -1
- package/dist/src/system_database.d.ts +1 -1
- package/dist/src/system_database.d.ts.map +1 -1
- package/dist/src/system_database.js +1 -1
- package/dist/src/system_database.js.map +1 -1
- package/dist/src/testing/testing_runtime.d.ts.map +1 -1
- package/dist/src/testing/testing_runtime.js +1 -2
- package/dist/src/testing/testing_runtime.js.map +1 -1
- package/dist/src/workflow.d.ts +4 -4
- package/dist/src/workflow.d.ts.map +1 -1
- package/dist/src/workflow.js +1 -1
- package/dist/src/workflow.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/dbos.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.InitContext = exports.DBOS = void 0;
|
3
|
+
exports.InitContext = exports.DBOS = exports.runAsWorkflowStep = exports.getExecutor = void 0;
|
4
4
|
const context_1 = require("./context");
|
5
5
|
const dbos_executor_1 = require("./dbos-executor");
|
6
6
|
const logs_1 = require("./telemetry/logs");
|
@@ -54,6 +54,30 @@ function augmentProxy(target, proxy) {
|
|
54
54
|
proto = Object.getPrototypeOf(proto);
|
55
55
|
}
|
56
56
|
}
|
57
|
+
function getExecutor() {
|
58
|
+
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
59
|
+
throw new error_1.DBOSExecutorNotInitializedError();
|
60
|
+
}
|
61
|
+
return dbos_executor_1.DBOSExecutor.globalInstance;
|
62
|
+
}
|
63
|
+
exports.getExecutor = getExecutor;
|
64
|
+
function runAsWorkflowStep(callback, funcName, childWFID) {
|
65
|
+
if (DBOS.isWithinWorkflow()) {
|
66
|
+
if (DBOS.isInStep()) {
|
67
|
+
// OK to use directly
|
68
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
69
|
+
}
|
70
|
+
else if (DBOS.isInWorkflow()) {
|
71
|
+
const wfctx = (0, context_1.assertCurrentWorkflowContext)();
|
72
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, DBOS.workflowID, wfctx.functionIDGetIncrement(), childWFID);
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to \`${funcName}\` inside a \`transaction\` or \`procedure\``);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
79
|
+
}
|
80
|
+
exports.runAsWorkflowStep = runAsWorkflowStep;
|
57
81
|
class DBOS {
|
58
82
|
///////
|
59
83
|
// Lifecycle
|
@@ -76,16 +100,16 @@ class DBOS {
|
|
76
100
|
* @param runtimeConfig - configuration of runtime access to DBOS
|
77
101
|
*/
|
78
102
|
static setConfig(config, runtimeConfig) {
|
79
|
-
DBOS
|
80
|
-
DBOS
|
103
|
+
DBOS.#dbosConfig = config;
|
104
|
+
DBOS.#runtimeConfig = runtimeConfig;
|
81
105
|
DBOS.translateConfig();
|
82
106
|
}
|
83
107
|
static translateConfig() {
|
84
|
-
if (DBOS
|
108
|
+
if (DBOS.#dbosConfig && !(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS.#dbosConfig)) {
|
85
109
|
const isDebugging = DBOS.getDebugModeFromEnv() !== dbos_executor_1.DebugMode.DISABLED;
|
86
|
-
[DBOS
|
110
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.translatePublicDBOSconfig)(DBOS.#dbosConfig, isDebugging);
|
87
111
|
if (process.env.DBOS__CLOUD === 'true') {
|
88
|
-
[DBOS
|
112
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.overwrite_config)(DBOS.#dbosConfig, DBOS.#runtimeConfig);
|
89
113
|
}
|
90
114
|
}
|
91
115
|
}
|
@@ -94,7 +118,7 @@ class DBOS {
|
|
94
118
|
* Use `setConfig`
|
95
119
|
*/
|
96
120
|
static setAppConfig(key, newValue) {
|
97
|
-
const conf = DBOS
|
121
|
+
const conf = DBOS.#dbosConfig?.application;
|
98
122
|
if (!conf)
|
99
123
|
throw new error_1.DBOSExecutorNotInitializedError();
|
100
124
|
(0, lodash_1.set)(conf, key, newValue);
|
@@ -104,11 +128,11 @@ class DBOS {
|
|
104
128
|
* USE IN TESTS ONLY - ALL WORKFLOWS, QUEUES, ETC. WILL BE LOST.
|
105
129
|
*/
|
106
130
|
static async dropSystemDB() {
|
107
|
-
if (!DBOS
|
108
|
-
DBOS
|
131
|
+
if (!DBOS.#dbosConfig) {
|
132
|
+
DBOS.#dbosConfig = (0, config_1.parseConfigFile)()[0];
|
109
133
|
}
|
110
134
|
DBOS.translateConfig();
|
111
|
-
return system_database_1.PostgresSystemDatabase.dropSystemDB(DBOS
|
135
|
+
return system_database_1.PostgresSystemDatabase.dropSystemDB(DBOS.#dbosConfig);
|
112
136
|
}
|
113
137
|
/**
|
114
138
|
* Use ORMEntities to set up database schema.
|
@@ -151,21 +175,20 @@ class DBOS {
|
|
151
175
|
utils_1.globalParams.executorID = (0, node_crypto_1.randomUUID)();
|
152
176
|
}
|
153
177
|
// Initialize the DBOS executor
|
154
|
-
if (!DBOS
|
155
|
-
[DBOS
|
178
|
+
if (!DBOS.#dbosConfig) {
|
179
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.parseConfigFile)({ forceConsole: isDebugging });
|
156
180
|
}
|
157
|
-
else if (!(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS
|
181
|
+
else if (!(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS.#dbosConfig)) {
|
158
182
|
DBOS.translateConfig(); // This is a defensive measure for users who'd do DBOS.config = X instead of using DBOS.setConfig()
|
159
183
|
}
|
160
|
-
if (!DBOS
|
184
|
+
if (!DBOS.#dbosConfig) {
|
161
185
|
throw new error_1.DBOSError('DBOS configuration not set');
|
162
186
|
}
|
163
187
|
dbos_executor_1.DBOSExecutor.createInternalQueue();
|
164
|
-
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(DBOS
|
188
|
+
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(DBOS.#dbosConfig, {
|
165
189
|
debugMode,
|
166
190
|
});
|
167
191
|
const executor = dbos_executor_1.DBOSExecutor.globalInstance;
|
168
|
-
DBOS.globalLogger = executor.logger;
|
169
192
|
await executor.init();
|
170
193
|
const debugWorkflowId = process.env.DBOS_DEBUG_WORKFLOW_ID;
|
171
194
|
if (debugWorkflowId) {
|
@@ -188,14 +211,14 @@ class DBOS {
|
|
188
211
|
}
|
189
212
|
// Start the DBOS admin server
|
190
213
|
const logger = DBOS.logger;
|
191
|
-
if (DBOS
|
214
|
+
if (DBOS.#runtimeConfig && DBOS.#runtimeConfig.runAdminServer) {
|
192
215
|
const adminApp = server_1.DBOSHttpServer.setupAdminApp(executor);
|
193
216
|
try {
|
194
|
-
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(DBOS
|
217
|
+
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(DBOS.#runtimeConfig.admin_port, logger);
|
195
218
|
// Wrap the listen call in a promise to properly catch errors
|
196
219
|
DBOS.adminServer = await new Promise((resolve, reject) => {
|
197
|
-
const server = adminApp.listen(DBOS
|
198
|
-
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${DBOS
|
220
|
+
const server = adminApp.listen(DBOS.#runtimeConfig?.admin_port, () => {
|
221
|
+
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${DBOS.#runtimeConfig?.admin_port}`);
|
199
222
|
resolve(server);
|
200
223
|
});
|
201
224
|
server.on('error', (err) => {
|
@@ -204,7 +227,7 @@ class DBOS {
|
|
204
227
|
});
|
205
228
|
}
|
206
229
|
catch (e) {
|
207
|
-
logger.warn(`Unable to start DBOS admin server on port ${DBOS
|
230
|
+
logger.warn(`Unable to start DBOS admin server on port ${DBOS.#runtimeConfig.admin_port}`);
|
208
231
|
}
|
209
232
|
}
|
210
233
|
if (options?.koaApp) {
|
@@ -296,14 +319,9 @@ class DBOS {
|
|
296
319
|
static async initEventReceivers() {
|
297
320
|
return dbos_executor_1.DBOSExecutor.globalInstance?.initEventReceivers();
|
298
321
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
static get executor() {
|
303
|
-
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
304
|
-
throw new error_1.DBOSExecutorNotInitializedError();
|
305
|
-
}
|
306
|
-
return dbos_executor_1.DBOSExecutor.globalInstance;
|
322
|
+
// Global DBOS executor instance
|
323
|
+
static get #executor() {
|
324
|
+
return getExecutor();
|
307
325
|
}
|
308
326
|
/**
|
309
327
|
* Creates a node.js HTTP handler for all entrypoints registered with `@DBOS.getApi`
|
@@ -326,9 +344,9 @@ class DBOS {
|
|
326
344
|
*/
|
327
345
|
static async launchAppHTTPServer() {
|
328
346
|
const server = DBOS.setUpHandlerCallback();
|
329
|
-
if (DBOS
|
347
|
+
if (DBOS.#runtimeConfig) {
|
330
348
|
// This will not listen if there's no decorated endpoint
|
331
|
-
DBOS.appServer = await server.appListen(DBOS
|
349
|
+
DBOS.appServer = await server.appListen(DBOS.#runtimeConfig.port);
|
332
350
|
}
|
333
351
|
}
|
334
352
|
/**
|
@@ -353,10 +371,12 @@ class DBOS {
|
|
353
371
|
//////
|
354
372
|
// Globals
|
355
373
|
//////
|
356
|
-
static
|
357
|
-
static
|
358
|
-
static
|
359
|
-
static
|
374
|
+
static #dbosConfig;
|
375
|
+
static #runtimeConfig = undefined;
|
376
|
+
static #invokeWrappers = new Map();
|
377
|
+
static get dbosConfig() {
|
378
|
+
return DBOS.#dbosConfig;
|
379
|
+
}
|
360
380
|
//////
|
361
381
|
// Context
|
362
382
|
//////
|
@@ -477,8 +497,8 @@ class DBOS {
|
|
477
497
|
*/
|
478
498
|
static get pgClient() {
|
479
499
|
const client = DBOS.sqlClient;
|
480
|
-
if (!DBOS.isInStoredProc() && DBOS
|
481
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.pgClient' but client is configured with type '${DBOS
|
500
|
+
if (!DBOS.isInStoredProc() && DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.PGNODE) {
|
501
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.pgClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
482
502
|
}
|
483
503
|
return client;
|
484
504
|
}
|
@@ -490,8 +510,8 @@ class DBOS {
|
|
490
510
|
if (DBOS.isInStoredProc()) {
|
491
511
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' from within a stored procedure`);
|
492
512
|
}
|
493
|
-
if (DBOS
|
494
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' but client is configured with type '${DBOS
|
513
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.KNEX) {
|
514
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
495
515
|
}
|
496
516
|
const client = DBOS.sqlClient;
|
497
517
|
return client;
|
@@ -504,8 +524,8 @@ class DBOS {
|
|
504
524
|
if (DBOS.isInStoredProc()) {
|
505
525
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' from within a stored procedure`);
|
506
526
|
}
|
507
|
-
if (DBOS
|
508
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' but client is configured with type '${DBOS
|
527
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.PRISMA) {
|
528
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
509
529
|
}
|
510
530
|
const client = DBOS.sqlClient;
|
511
531
|
return client;
|
@@ -518,8 +538,8 @@ class DBOS {
|
|
518
538
|
if (DBOS.isInStoredProc()) {
|
519
539
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' from within a stored procedure`);
|
520
540
|
}
|
521
|
-
if (DBOS
|
522
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' but client is configured with type '${DBOS
|
541
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.TYPEORM) {
|
542
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
523
543
|
}
|
524
544
|
const client = DBOS.sqlClient;
|
525
545
|
return client;
|
@@ -532,8 +552,8 @@ class DBOS {
|
|
532
552
|
if (DBOS.isInStoredProc()) {
|
533
553
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' from within a stored procedure`);
|
534
554
|
}
|
535
|
-
if (DBOS
|
536
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' but client is configured with type '${DBOS
|
555
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.DRIZZLE) {
|
556
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
537
557
|
}
|
538
558
|
const client = DBOS.sqlClient;
|
539
559
|
return client;
|
@@ -550,8 +570,8 @@ class DBOS {
|
|
550
570
|
return ctx.getConfig(key, defaultValue);
|
551
571
|
if (ctx)
|
552
572
|
return ctx.getConfig(key);
|
553
|
-
if (DBOS
|
554
|
-
return DBOS
|
573
|
+
if (DBOS.#executor)
|
574
|
+
return DBOS.#executor.getConfig(key, defaultValue);
|
555
575
|
return defaultValue;
|
556
576
|
}
|
557
577
|
/**
|
@@ -565,7 +585,7 @@ class DBOS {
|
|
565
585
|
if (DBOS.isWithinWorkflow() && !DBOS.isInStep()) {
|
566
586
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `queryUserDB` inside a `workflow`, without being in a `step`');
|
567
587
|
}
|
568
|
-
return DBOS
|
588
|
+
return DBOS.#executor.queryUserDB(sql, params);
|
569
589
|
}
|
570
590
|
//////
|
571
591
|
// Access to system DB, for event receivers etc.
|
@@ -586,7 +606,7 @@ class DBOS {
|
|
586
606
|
* @returns The latest system database state for the specified service+workflow+item
|
587
607
|
*/
|
588
608
|
static async getEventDispatchState(svc, wfn, key) {
|
589
|
-
return await DBOS
|
609
|
+
return await DBOS.#executor.getEventDispatchState(svc, wfn, key);
|
590
610
|
}
|
591
611
|
/**
|
592
612
|
* Set a state item into the system database, which provides a key/value store interface for event dispatchers.
|
@@ -598,26 +618,13 @@ class DBOS {
|
|
598
618
|
* @returns The upsert returns the current record, which may be useful if it is more recent than the `state` provided.
|
599
619
|
*/
|
600
620
|
static async upsertEventDispatchState(state) {
|
601
|
-
return await DBOS
|
621
|
+
return await DBOS.#executor.upsertEventDispatchState(state);
|
602
622
|
}
|
603
623
|
//////
|
604
624
|
// Workflow and other operations
|
605
625
|
//////
|
606
|
-
static runAsWorkflowStep(callback, funcName
|
607
|
-
|
608
|
-
if (DBOS.isInStep()) {
|
609
|
-
// OK to use directly
|
610
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
611
|
-
}
|
612
|
-
else if (DBOS.isInWorkflow()) {
|
613
|
-
const wfctx = (0, context_1.assertCurrentWorkflowContext)();
|
614
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, DBOS.workflowID, wfctx.functionIDGetIncrement(), childWFID);
|
615
|
-
}
|
616
|
-
else {
|
617
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to \`${funcName}\` inside a \`transaction\` or \`procedure\``);
|
618
|
-
}
|
619
|
-
}
|
620
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
626
|
+
static #runAsWorkflowStep(callback, funcName) {
|
627
|
+
return runAsWorkflowStep(callback, funcName);
|
621
628
|
}
|
622
629
|
/**
|
623
630
|
* Get the workflow status given a workflow ID
|
@@ -628,17 +635,17 @@ class DBOS {
|
|
628
635
|
if (DBOS.isWithinWorkflow()) {
|
629
636
|
if (DBOS.isInStep()) {
|
630
637
|
// OK to use directly
|
631
|
-
return DBOS
|
638
|
+
return DBOS.#executor.getWorkflowStatus(workflowID);
|
632
639
|
}
|
633
640
|
else if (DBOS.isInWorkflow()) {
|
634
641
|
const wfctx = (0, context_1.assertCurrentWorkflowContext)();
|
635
|
-
return DBOS
|
642
|
+
return DBOS.#executor.getWorkflowStatus(workflowID, DBOS.workflowID, wfctx.functionIDGetIncrement());
|
636
643
|
}
|
637
644
|
else {
|
638
645
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `getWorkflowStatus` inside a `transaction` or `procedure`');
|
639
646
|
}
|
640
647
|
}
|
641
|
-
return DBOS
|
648
|
+
return DBOS.#executor.getWorkflowStatus(workflowID);
|
642
649
|
}
|
643
650
|
/**
|
644
651
|
* Get the workflow result, given a workflow ID
|
@@ -651,12 +658,13 @@ class DBOS {
|
|
651
658
|
if (DBOS.isWithinWorkflow() && timeoutSeconds !== undefined) {
|
652
659
|
timerFuncID = (0, context_1.assertCurrentWorkflowContext)().functionIDGetIncrement();
|
653
660
|
}
|
654
|
-
return await
|
661
|
+
return await runAsWorkflowStep(async () => {
|
655
662
|
const rres = await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.awaitWorkflowResult(workflowID, timeoutSeconds, DBOS.workflowID, timerFuncID);
|
656
663
|
if (!rres)
|
657
664
|
return null;
|
658
|
-
if (rres?.cancelled)
|
659
|
-
throw new error_1.
|
665
|
+
if (rres?.cancelled) {
|
666
|
+
throw new error_1.DBOSAwaitedWorkflowCancelledError(workflowID);
|
667
|
+
}
|
660
668
|
return dbos_executor_1.DBOSExecutor.reviveResultOrError(rres);
|
661
669
|
}, 'DBOS.getResult', workflowID);
|
662
670
|
}
|
@@ -674,7 +682,7 @@ class DBOS {
|
|
674
682
|
}
|
675
683
|
return (0, context_1.getCurrentDBOSContext)().retrieveWorkflow(workflowID);
|
676
684
|
}
|
677
|
-
return DBOS
|
685
|
+
return DBOS.#executor.retrieveWorkflow(workflowID);
|
678
686
|
}
|
679
687
|
/**
|
680
688
|
* Query the system database for all workflows matching the provided predicate
|
@@ -683,8 +691,8 @@ class DBOS {
|
|
683
691
|
* @deprecated Use `DBOS.listWorkflows` instead
|
684
692
|
*/
|
685
693
|
static async getWorkflows(input) {
|
686
|
-
return await DBOS
|
687
|
-
const wfs = await DBOS
|
694
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
695
|
+
const wfs = await DBOS.#executor.listWorkflows(input);
|
688
696
|
return { workflowUUIDs: wfs.map((wf) => wf.workflowID) };
|
689
697
|
}, 'DBOS.getWorkflows');
|
690
698
|
}
|
@@ -694,8 +702,8 @@ class DBOS {
|
|
694
702
|
* @returns `WorkflowStatus` array containing details of the matching workflows
|
695
703
|
*/
|
696
704
|
static async listWorkflows(input) {
|
697
|
-
return await DBOS
|
698
|
-
return await DBOS
|
705
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
706
|
+
return await DBOS.#executor.listWorkflows(input);
|
699
707
|
}, 'DBOS.listWorkflows');
|
700
708
|
}
|
701
709
|
/**
|
@@ -704,8 +712,8 @@ class DBOS {
|
|
704
712
|
* @returns `WorkflowStatus` array containing details of the matching workflows
|
705
713
|
*/
|
706
714
|
static async listQueuedWorkflows(input) {
|
707
|
-
return await DBOS
|
708
|
-
return await DBOS
|
715
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
716
|
+
return await DBOS.#executor.listQueuedWorkflows(input);
|
709
717
|
}, 'DBOS.listQueuedWorkflows');
|
710
718
|
}
|
711
719
|
/**
|
@@ -714,8 +722,8 @@ class DBOS {
|
|
714
722
|
* @returns `StepInfo` array listing the executed steps of the workflow. If the workflow is not found, `undefined` is returned.
|
715
723
|
*/
|
716
724
|
static async listWorkflowSteps(workflowID) {
|
717
|
-
return await DBOS
|
718
|
-
return await DBOS
|
725
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
726
|
+
return await DBOS.#executor.listWorkflowSteps(workflowID);
|
719
727
|
}, 'DBOS.listWorkflowSteps');
|
720
728
|
}
|
721
729
|
/**
|
@@ -725,8 +733,8 @@ class DBOS {
|
|
725
733
|
* @param workflowID - ID of the workflow
|
726
734
|
*/
|
727
735
|
static async cancelWorkflow(workflowID) {
|
728
|
-
return await DBOS
|
729
|
-
return await DBOS
|
736
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
737
|
+
return await DBOS.#executor.cancelWorkflow(workflowID);
|
730
738
|
}, 'DBOS.cancelWorkflow');
|
731
739
|
}
|
732
740
|
/**
|
@@ -734,8 +742,8 @@ class DBOS {
|
|
734
742
|
* @param workflowID - ID of the workflow
|
735
743
|
*/
|
736
744
|
static async resumeWorkflow(workflowID) {
|
737
|
-
await DBOS
|
738
|
-
return await DBOS
|
745
|
+
await DBOS.#runAsWorkflowStep(async () => {
|
746
|
+
return await DBOS.#executor.resumeWorkflow(workflowID);
|
739
747
|
}, 'DBOS.resumeWorkflow');
|
740
748
|
return this.retrieveWorkflow(workflowID);
|
741
749
|
}
|
@@ -748,8 +756,8 @@ class DBOS {
|
|
748
756
|
* @throws DBOSInvalidStepIDError if the `startStep` is greater than the maximum step ID of the workflow
|
749
757
|
*/
|
750
758
|
static async forkWorkflow(workflowID, startStep, options) {
|
751
|
-
const forkedID = await DBOS
|
752
|
-
return await DBOS
|
759
|
+
const forkedID = await DBOS.#runAsWorkflowStep(async () => {
|
760
|
+
return await DBOS.#executor.forkWorkflow(workflowID, startStep, options);
|
753
761
|
}, 'DBOS.forkWorkflow');
|
754
762
|
return this.retrieveWorkflow(forkedID);
|
755
763
|
}
|
@@ -758,8 +766,8 @@ class DBOS {
|
|
758
766
|
* @param input - Filter predicate, containing the queue name and other criteria
|
759
767
|
*/
|
760
768
|
static async getWorkflowQueue(input) {
|
761
|
-
return await DBOS
|
762
|
-
return await DBOS
|
769
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
770
|
+
return await DBOS.#executor.getWorkflowQueue(input);
|
763
771
|
}, 'DBOS.getWorkflowQueue');
|
764
772
|
}
|
765
773
|
/**
|
@@ -944,6 +952,11 @@ class DBOS {
|
|
944
952
|
deadlineEpochMS: wfctx.deadlineEpochMS,
|
945
953
|
enqueueOptions: inParams?.enqueueOptions,
|
946
954
|
};
|
955
|
+
// Detach child deadline if a null timeout is configured
|
956
|
+
// We must check the inParams but also pctx (if the workflow was called withWorkflowTimeout)
|
957
|
+
if (inParams?.timeoutMS === null || pctx?.workflowTimeoutMS === null) {
|
958
|
+
wfParams.deadlineEpochMS = undefined;
|
959
|
+
}
|
947
960
|
for (const op of ops) {
|
948
961
|
if (op.workflowConfig) {
|
949
962
|
proxy[op.name] = (...args) => dbos_executor_1.DBOSExecutor.globalInstance.internalWorkflow(op.registeredFunction, wfParams, wfctx.workflowUUID, funcId, ...args);
|
@@ -973,7 +986,7 @@ class DBOS {
|
|
973
986
|
// If pctx has no span, e.g., has not been setup through `withTracedContext`, set up a parent span for the workflow here.
|
974
987
|
let span = pctx.span;
|
975
988
|
if (!span) {
|
976
|
-
span = DBOS
|
989
|
+
span = DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'startWorkflow', {
|
977
990
|
operationUUID: wfId,
|
978
991
|
operationType: pctx.operationType,
|
979
992
|
authenticatedUser: pctx.authenticatedUser,
|
@@ -998,7 +1011,7 @@ class DBOS {
|
|
998
1011
|
};
|
999
1012
|
for (const op of ops) {
|
1000
1013
|
if (op.workflowConfig) {
|
1001
|
-
proxy[op.name] = (...args) => DBOS
|
1014
|
+
proxy[op.name] = (...args) => DBOS.#executor.workflow(op.registeredFunction, wfParams, ...args);
|
1002
1015
|
}
|
1003
1016
|
else if (op.txnConfig) {
|
1004
1017
|
const txn = op.registeredFunction;
|
@@ -1022,7 +1035,7 @@ class DBOS {
|
|
1022
1035
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1023
1036
|
let span = pctx?.span;
|
1024
1037
|
if (!span) {
|
1025
|
-
span = DBOS
|
1038
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1026
1039
|
operationType: pctx?.operationType,
|
1027
1040
|
authenticatedUser: pctx?.authenticatedUser,
|
1028
1041
|
assumedRole: pctx?.assumedRole,
|
@@ -1136,7 +1149,7 @@ class DBOS {
|
|
1136
1149
|
}
|
1137
1150
|
return (0, context_1.getCurrentDBOSContext)().send(destinationID, message, topic);
|
1138
1151
|
}
|
1139
|
-
return DBOS
|
1152
|
+
return DBOS.#executor.send(destinationID, message, topic, idempotencyKey);
|
1140
1153
|
}
|
1141
1154
|
/**
|
1142
1155
|
* Receive a message on optional `topic` from within a workflow.
|
@@ -1196,7 +1209,7 @@ class DBOS {
|
|
1196
1209
|
}
|
1197
1210
|
return (0, context_1.getCurrentDBOSContext)().getEvent(workflowID, key, timeoutSeconds);
|
1198
1211
|
}
|
1199
|
-
return DBOS
|
1212
|
+
return DBOS.#executor.getEvent(workflowID, key, timeoutSeconds);
|
1200
1213
|
}
|
1201
1214
|
//////
|
1202
1215
|
// Decorators
|
@@ -1254,6 +1267,10 @@ class DBOS {
|
|
1254
1267
|
timeoutMS: pctx?.workflowTimeoutMS,
|
1255
1268
|
deadlineEpochMS: wfctx.deadlineEpochMS,
|
1256
1269
|
};
|
1270
|
+
// Detach child deadline if a null timeout is configured
|
1271
|
+
if (pctx?.workflowTimeoutMS === null) {
|
1272
|
+
params.deadlineEpochMS = undefined;
|
1273
|
+
}
|
1257
1274
|
const cwfh = await dbos_executor_1.DBOSExecutor.globalInstance.internalWorkflow(registration.registeredFunction, params, wfctx.workflowUUID, funcId, ...rawArgs);
|
1258
1275
|
return await cwfh.getResult();
|
1259
1276
|
}
|
@@ -1263,7 +1280,7 @@ class DBOS {
|
|
1263
1280
|
// If pctx has no span, e.g., has not been setup through `withTracedContext`, set up a parent span for the workflow here.
|
1264
1281
|
let span = pctx.span;
|
1265
1282
|
if (!span) {
|
1266
|
-
span = DBOS
|
1283
|
+
span = DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'workflowCaller', {
|
1267
1284
|
operationUUID: wfId,
|
1268
1285
|
operationType: pctx.operationType,
|
1269
1286
|
authenticatedUser: pctx.authenticatedUser,
|
@@ -1285,7 +1302,7 @@ class DBOS {
|
|
1285
1302
|
parentCtx,
|
1286
1303
|
timeoutMS: pctx?.workflowTimeoutMS,
|
1287
1304
|
};
|
1288
|
-
const handle = await DBOS
|
1305
|
+
const handle = await DBOS.#executor.workflow(registration.registeredFunction, wfParams, ...rawArgs);
|
1289
1306
|
return await handle.getResult();
|
1290
1307
|
};
|
1291
1308
|
descriptor.value = invokeWrapper;
|
@@ -1295,7 +1312,7 @@ class DBOS {
|
|
1295
1312
|
});
|
1296
1313
|
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1297
1314
|
// TODO CTX this should not be in here already, or if it is we need to do something different...
|
1298
|
-
DBOS
|
1315
|
+
DBOS.#invokeWrappers.set(invokeWrapper, registration.registeredFunction);
|
1299
1316
|
return descriptor;
|
1300
1317
|
}
|
1301
1318
|
return decorator;
|
@@ -1335,7 +1352,7 @@ class DBOS {
|
|
1335
1352
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1336
1353
|
let span = pctx?.span;
|
1337
1354
|
if (!span) {
|
1338
|
-
span = DBOS
|
1355
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1339
1356
|
operationType: pctx?.operationType,
|
1340
1357
|
authenticatedUser: pctx?.authenticatedUser,
|
1341
1358
|
assumedRole: pctx?.assumedRole,
|
@@ -1358,7 +1375,7 @@ class DBOS {
|
|
1358
1375
|
parentCtx,
|
1359
1376
|
workflowUUID: wfId,
|
1360
1377
|
};
|
1361
|
-
return await DBOS
|
1378
|
+
return await DBOS.#executor.transaction(registration.registeredFunction, wfParams, ...rawArgs);
|
1362
1379
|
};
|
1363
1380
|
descriptor.value = invokeWrapper;
|
1364
1381
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1391,7 +1408,7 @@ class DBOS {
|
|
1391
1408
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1392
1409
|
let span = pctx?.span;
|
1393
1410
|
if (!span) {
|
1394
|
-
span = DBOS
|
1411
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1395
1412
|
operationType: pctx?.operationType,
|
1396
1413
|
authenticatedUser: pctx?.authenticatedUser,
|
1397
1414
|
assumedRole: pctx?.assumedRole,
|
@@ -1413,7 +1430,7 @@ class DBOS {
|
|
1413
1430
|
parentCtx,
|
1414
1431
|
workflowUUID: wfId,
|
1415
1432
|
};
|
1416
|
-
return await DBOS
|
1433
|
+
return await DBOS.#executor.procedure(registration.registeredFunction, wfParams, ...rawArgs);
|
1417
1434
|
};
|
1418
1435
|
descriptor.value = invokeWrapper;
|
1419
1436
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1462,7 +1479,7 @@ class DBOS {
|
|
1462
1479
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1463
1480
|
let span = pctx?.span;
|
1464
1481
|
if (!span) {
|
1465
|
-
span = DBOS
|
1482
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1466
1483
|
operationType: pctx?.operationType,
|
1467
1484
|
authenticatedUser: pctx?.authenticatedUser,
|
1468
1485
|
assumedRole: pctx?.assumedRole,
|
@@ -1485,7 +1502,7 @@ class DBOS {
|
|
1485
1502
|
parentCtx,
|
1486
1503
|
workflowUUID: wfId,
|
1487
1504
|
};
|
1488
|
-
return await DBOS
|
1505
|
+
return await DBOS.#executor.external(registration.registeredFunction, wfParams, ...rawArgs);
|
1489
1506
|
};
|
1490
1507
|
descriptor.value = invokeWrapper;
|
1491
1508
|
registration.wrappedFunction = invokeWrapper;
|