From bfd8280dea73323887770f9c24e18ec48a9711f1 Mon Sep 17 00:00:00 2001 From: manojdbos Date: Fri, 3 Jan 2025 08:42:19 -0800 Subject: [PATCH 1/9] debug statements --- src/dbos-executor.ts | 15 +++++++++++++++ src/dbos.ts | 2 ++ src/decorators.ts | 15 +++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/dbos-executor.ts b/src/dbos-executor.ts index cadefa6fe..b662cd8ba 100644 --- a/src/dbos-executor.ts +++ b/src/dbos-executor.ts @@ -184,6 +184,7 @@ export class DBOSExecutor implements DBOSExecutorContext { constructor(readonly config: DBOSConfig, systemDatabase?: SystemDatabase) { this.debugMode = config.debugMode ?? false; this.debugProxy = config.debugProxy; + console.log("start DBOSExecutor constructor") // Set configured environment variables if (config.env) { @@ -241,6 +242,8 @@ export class DBOSExecutor implements DBOSExecutorContext { this.initialized = false; DBOSExecutor.globalInstance = this; + + console.log("exit DBOSExecutor constructor") } configureDbClient() { @@ -313,6 +316,9 @@ export class DBOSExecutor implements DBOSExecutorContext { } #registerClass(cls: object) { + + console.log("Registering class", cls) + const registeredClassOperations = getRegisteredOperations(cls); this.registeredOperations.push(...registeredClassOperations); for (const ro of registeredClassOperations) { @@ -343,6 +349,7 @@ export class DBOSExecutor implements DBOSExecutorContext { } async init(classes?: object[]): Promise { + console.log("DbosExecutor init") if (this.initialized) { this.logger.error("Workflow executor already initialized!"); return; @@ -350,6 +357,7 @@ export class DBOSExecutor implements DBOSExecutorContext { if (!classes || !classes.length) { classes = getAllRegisteredClasses(); + console.log("registered Classes", classes) } type AnyConstructor = new (...args: unknown[]) => object; @@ -381,6 +389,7 @@ export class DBOSExecutor implements DBOSExecutorContext { } for (const cls of classes) { + console.log("Registering class", cls) this.#registerClass(cls); } @@ -502,6 +511,9 @@ export class DBOSExecutor implements DBOSExecutorContext { /* WORKFLOW OPERATIONS */ #registerWorkflow(ro: MethodRegistrationBase) { + + console.log("registering workflow") + const wf = ro.registeredFunction as Workflow; if (wf.name === DBOSExecutor.tempWorkflowName) { throw new DBOSError(`Unexpected use of reserved workflow name: ${wf.name}`); @@ -520,6 +532,9 @@ export class DBOSExecutor implements DBOSExecutorContext { } #registerTransaction(ro: MethodRegistrationBase) { + + console.log("registering transaction") + const txf = ro.registeredFunction as Transaction; const tfn = ro.className + '.' + ro.name; diff --git a/src/dbos.ts b/src/dbos.ts index bfdaa3aaf..9654305c4 100644 --- a/src/dbos.ts +++ b/src/dbos.ts @@ -151,6 +151,8 @@ export class DBOS { // Do nothing is DBOS is already initialized if (DBOSExecutor.globalInstance) return; + console.log("Launching DBOS.launch()"); + // Initialize the DBOS executor if (!DBOS.dbosConfig) { const [dbosConfig, runtimeConfig]: [DBOSConfig, DBOSRuntimeConfig] = parseConfigFile(); diff --git a/src/decorators.ts b/src/decorators.ts index 73c88fe10..467dca59f 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -455,6 +455,7 @@ export function registerAndWrapContextFreeFunction object; const classesByName: Map > = new Map(); export function getAllRegisteredClasses() { + console.log("We are in getAllRegisteredClasses"); + console.trace(); const ctors: AnyConstructor[] = []; for (const [_cn, creg] of classesByName) { ctors.push(creg.ctor); @@ -474,9 +477,19 @@ export function getAllRegisteredClasses() { export function getOrCreateClassRegistration( ctor: CT ) { + + console.log("We are in getOrCreateClassRegistration", ctor.name); + console.log("before number of regis", classesByName.size); + console.trace(); + const name = ctor.name; + console.log("ctor",ctor) if (!classesByName.has(name)) { + + console.log("Inserting class registration", name); classesByName.set(name, new ClassRegistration(ctor)); + console.log("Done Inserting class registration", name); + } const clsReg: ClassRegistration = classesByName.get(name)!; @@ -590,12 +603,14 @@ export function DefaultArgRequired(ctor: T) { + console.log("We are in DefaultArgOptional", ctor.name); const clsreg = getOrCreateClassRegistration(ctor); clsreg.defaultArgRequired = ArgRequiredOptions.OPTIONAL; } export function configureInstance(cls: new (name:string, ...args: T) => R, name: string, ...args: T) : R { + console.log("We are in configureInstance", cls.name, name); const inst = new cls(name, ...args); const creg = getOrCreateClassRegistration(cls as new(...args: unknown[])=>R); if (creg.configuredInstances.has(name)) { From 58f4182349816e963fedfa4e4a42962f8853893b Mon Sep 17 00:00:00 2001 From: manojdbos Date: Tue, 7 Jan 2025 06:50:59 -0800 Subject: [PATCH 2/9] register from multiple files working --- src/dbos-executor.ts | 16 ++++++++++++++-- src/dbos.ts | 6 +++++- src/decorators.ts | 34 ++++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/dbos-executor.ts b/src/dbos-executor.ts index b662cd8ba..f40ba6d45 100644 --- a/src/dbos-executor.ts +++ b/src/dbos-executor.ts @@ -319,7 +319,9 @@ export class DBOSExecutor implements DBOSExecutorContext { console.log("Registering class", cls) + const registeredClassOperations = getRegisteredOperations(cls); + console.log("registeredClassOperations", registeredClassOperations) this.registeredOperations.push(...registeredClassOperations); for (const ro of registeredClassOperations) { if (ro.workflowConfig) { @@ -351,7 +353,15 @@ export class DBOSExecutor implements DBOSExecutorContext { async init(classes?: object[]): Promise { console.log("DbosExecutor init") if (this.initialized) { - this.logger.error("Workflow executor already initialized!"); + if (!classes || !classes.length) { + classes = getAllRegisteredClasses(); + console.log("registered Classes", classes) + } + for (const cls of classes) { + console.log("Registering class", cls) + this.#registerClass(cls); + } + // this.logger.error("Workflow executor already initialized!"); return; } @@ -539,7 +549,9 @@ export class DBOSExecutor implements DBOSExecutorContext { const tfn = ro.className + '.' + ro.name; if (this.transactionInfoMap.has(tfn)) { - throw new DBOSError(`Repeated Transaction name: ${tfn}`); + // throw new DBOSError(`Repeated Transaction name: ${tfn}`); + console.log(`Repeated Transaction name: ${tfn}`); + return; } const txnInfo: TransactionRegInfo = { transaction: txf, diff --git a/src/dbos.ts b/src/dbos.ts index 9654305c4..8bc1980e9 100644 --- a/src/dbos.ts +++ b/src/dbos.ts @@ -149,7 +149,11 @@ export class DBOS { static async launch(httpApps?: DBOSHttpApps) { // Do nothing is DBOS is already initialized - if (DBOSExecutor.globalInstance) return; + if (DBOSExecutor.globalInstance) { + console.log("DBOS already initialized. But running init again"); + DBOSExecutor.globalInstance.init(); + return + } console.log("Launching DBOS.launch()"); diff --git a/src/decorators.ts b/src/decorators.ts index 467dca59f..c036db651 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -260,14 +260,20 @@ export function registerFunctionWrapper(func: unknown, reg: MethodRegistration { const registeredOperations: MethodRegistrationBase[] = []; + console.log("We are in getRegisteredOperations") + + const clname = (target as any).mjclassName + if (typeof target === 'function') { // Constructor case - const classReg = classesByName.get(target.name); + // const classReg = classesByName.get(target.name); + const classReg = classesByName.get(clname); classReg?.registeredOperations?.forEach((m) =>registeredOperations.push(m)); } else { let current: object | undefined = target; while (current) { - const cname = current.constructor.name; + // const cname = current.constructor.name; + const cname = clname; if (classesByName.has(cname)) { registeredOperations.push(...getRegisteredOperations(current.constructor)); } @@ -334,7 +340,7 @@ function getOrCreateMethodRegistration( isInstance = true; } - const classReg = getOrCreateClassRegistration(regtarget); + const classReg = getOrCreateClassRegistration(regtarget, propertyKey); const fname = propertyKey.toString(); if (!classReg.registeredOperations.has(fname)) { @@ -455,7 +461,7 @@ export function registerAndWrapContextFreeFunction object; const classesByName: Map > = new Map(); export function getAllRegisteredClasses() { - console.log("We are in getAllRegisteredClasses"); - console.trace(); const ctors: AnyConstructor[] = []; for (const [_cn, creg] of classesByName) { ctors.push(creg.ctor); @@ -475,15 +479,17 @@ export function getAllRegisteredClasses() { } export function getOrCreateClassRegistration( - ctor: CT + ctor: CT, propertyKey?: string | symbol ) { - console.log("We are in getOrCreateClassRegistration", ctor.name); - console.log("before number of regis", classesByName.size); - console.trace(); + console.log("We are in getOrCreateClassRegistration", ctor); + // console.log("before number of regis", classesByName.size); + // console.trace(); - const name = ctor.name; - console.log("ctor",ctor) + // const name = ctor.name; + // const name = propertyKey ? propertyKey.toString() : ctor.name; + const name: string = (ctor as any).mjclassName + console.log("name we are using ",name) if (!classesByName.has(name)) { console.log("Inserting class registration", name); @@ -491,6 +497,8 @@ export function getOrCreateClassRegistration = classesByName.get(name)!; if (clsReg.needsInitialized) { @@ -658,6 +666,8 @@ export function Transaction(config: TransactionConfig={}) { // eslint-disable-next-line @typescript-eslint/no-explicit-any inDescriptor: TypedPropertyDescriptor<(this: This, ctx: TransactionContext, ...args: Args) => Promise>) { + const className = (target as any).constructor.mjclassName; + console.log("In Transaction decorator Class Name:", className, propertyKey); const { descriptor, registration } = registerAndWrapFunction(target, propertyKey, inDescriptor); registration.txnConfig = config; return descriptor; From bceb29bb362d11a4ad4292b133236bc076fd2358 Mon Sep 17 00:00:00 2001 From: manojdbos Date: Wed, 8 Jan 2025 14:54:29 -0800 Subject: [PATCH 3/9] DBOS.register working --- src/dbos-executor.ts | 29 ++++++++++++++++++++++++----- src/dbos.ts | 20 ++++++++++++++++++-- src/decorators.ts | 11 ++++++++++- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/dbos-executor.ts b/src/dbos-executor.ts index f40ba6d45..fbe72b5ac 100644 --- a/src/dbos-executor.ts +++ b/src/dbos-executor.ts @@ -38,7 +38,7 @@ import { DrizzleUserDatabase, UserDatabaseClient, } from './user_database'; -import { MethodRegistrationBase, getRegisteredOperations, getOrCreateClassRegistration, MethodRegistration, getRegisteredMethodClassName, getRegisteredMethodName, getConfiguredInstance, ConfiguredInstance, getAllRegisteredClasses } from './decorators'; +import { MethodRegistrationBase, getRegisteredOperations, getOrCreateClassRegistration, MethodRegistration, getRegisteredMethodClassName, getRegisteredMethodName, getConfiguredInstance, ConfiguredInstance, getAllRegisteredClasses,getRegisteredClassByName } from './decorators'; import { SpanStatusCode } from '@opentelemetry/api'; import knex, { Knex } from 'knex'; import { DBOSContextImpl, InitContext, runWithWorkflowContext, runWithTransactionContext, runWithStepContext } from './context'; @@ -315,13 +315,31 @@ export class DBOSExecutor implements DBOSExecutorContext { } } + registerClass(className: string) { + + console.log("DBOSExecutor Registering class", className) + + const cls = getRegisteredClassByName(className); + + if (cls === undefined) { + throw new DBOSError(`Class ${className} not found`); + } + + // this.#registerClass(cls); + this.#registerClass(cls.ctor); + + + // cls.regComplete = true; + } + + #registerClass(cls: object) { - console.log("Registering class", cls) + console.log("#Registering class", cls) const registeredClassOperations = getRegisteredOperations(cls); - console.log("registeredClassOperations", registeredClassOperations) + // console.log("registeredClassOperations", registeredClassOperations) this.registeredOperations.push(...registeredClassOperations); for (const ro of registeredClassOperations) { if (ro.workflowConfig) { @@ -353,6 +371,7 @@ export class DBOSExecutor implements DBOSExecutorContext { async init(classes?: object[]): Promise { console.log("DbosExecutor init") if (this.initialized) { + /* this.logger.error("Workflow executor already initialized!"); if (!classes || !classes.length) { classes = getAllRegisteredClasses(); console.log("registered Classes", classes) @@ -360,8 +379,8 @@ export class DBOSExecutor implements DBOSExecutorContext { for (const cls of classes) { console.log("Registering class", cls) this.#registerClass(cls); - } - // this.logger.error("Workflow executor already initialized!"); + } */ + this.logger.error("Workflow executor already initialized!"); return; } diff --git a/src/dbos.ts b/src/dbos.ts index 8bc1980e9..43f56262a 100644 --- a/src/dbos.ts +++ b/src/dbos.ts @@ -147,11 +147,27 @@ export class DBOS { set(conf, key, newValue); } + static async register(cls: any) { + + console.log("DBOS.register class: ", cls.mjclassName); + + await this.launch(); + + const executor = DBOSExecutor.globalInstance; + + if (executor !== undefined) { + executor.registerClass(cls.mjclassName); + } else { + throw new DBOSExecutorNotInitializedError(); + } + + } + static async launch(httpApps?: DBOSHttpApps) { // Do nothing is DBOS is already initialized if (DBOSExecutor.globalInstance) { - console.log("DBOS already initialized. But running init again"); - DBOSExecutor.globalInstance.init(); + // console.log("DBOS already initialized. But running init again"); + // DBOSExecutor.globalInstance.init(); return } diff --git a/src/decorators.ts b/src/decorators.ts index c036db651..a020a054b 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -260,13 +260,17 @@ export function registerFunctionWrapper(func: unknown, reg: MethodRegistration { const registeredOperations: MethodRegistrationBase[] = []; - console.log("We are in getRegisteredOperations") + const clname = (target as any).mjclassName + console.log("We are in getRegisteredOperations", clname) + + if (typeof target === 'function') { // Constructor case // const classReg = classesByName.get(target.name); const classReg = classesByName.get(clname); + console.log("function classReg", classReg) classReg?.registeredOperations?.forEach((m) =>registeredOperations.push(m)); } else { @@ -274,6 +278,7 @@ export function getRegisteredOperations(target: object): ReadonlyArray object; const classesByName: Map > = new Map(); +export function getRegisteredClassByName(name: string) { + return classesByName.get(name); +} + export function getAllRegisteredClasses() { const ctors: AnyConstructor[] = []; for (const [_cn, creg] of classesByName) { From 3fa8eea02a54a47b9018b1344533efd8f83d26a2 Mon Sep 17 00:00:00 2001 From: manojdbos Date: Wed, 8 Jan 2025 17:23:37 -0800 Subject: [PATCH 4/9] all working --- src/dbos.ts | 10 ++++++++-- src/decorators.ts | 28 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/dbos.ts b/src/dbos.ts index 43f56262a..988789366 100644 --- a/src/dbos.ts +++ b/src/dbos.ts @@ -149,14 +149,15 @@ export class DBOS { static async register(cls: any) { - console.log("DBOS.register class: ", cls.mjclassName); + console.log("DBOS.register class: ", cls.name); await this.launch(); const executor = DBOSExecutor.globalInstance; if (executor !== undefined) { - executor.registerClass(cls.mjclassName); + // executor.registerClass(cls.mjclassName); + executor.registerClass(cls.name) } else { throw new DBOSExecutorNotInitializedError(); } @@ -837,6 +838,11 @@ export class DBOS { propertyKey: string, inDescriptor: TypedPropertyDescriptor<(this: This, ...args: Args) => Promise>) { + + console.log("mjjjj Transaction decorator called"); + + + const { descriptor, registration } = registerAndWrapContextFreeFunction(target, propertyKey, inDescriptor); registration.txnConfig = config; diff --git a/src/decorators.ts b/src/decorators.ts index a020a054b..4492cd534 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -262,22 +262,22 @@ export function getRegisteredOperations(target: object): ReadonlyArrayregisteredOperations.push(m)); } else { let current: object | undefined = target; while (current) { - // const cname = current.constructor.name; - const cname = clname; + const cname = current.constructor.name; + // const cname = clname; console.log("not a function classReg", cname, classesByName) if (classesByName.has(cname)) { registeredOperations.push(...getRegisteredOperations(current.constructor)); @@ -456,6 +456,7 @@ export function registerAndWrapFunction(ta throw Error("Use of decorator when original method is undefined"); } + const registration = getOrCreateMethodRegistration(target, propertyKey, descriptor, true); return { descriptor, registration }; @@ -465,8 +466,10 @@ export function registerAndWrapContextFreeFunction, ...args: Args) => Promise>) { + + console.log("mjjjj We are in Transaction decorator", target, propertyKey, inDescriptor); + const xxxName = Reflect.getMetadata('design:type', target)?.name ?? 'UnknownClass'; + + console.log(`Transaction decorator applied to: ${xxxName}.${propertyKey}`); + + const className = (target as any).constructor.mjclassName; console.log("In Transaction decorator Class Name:", className, propertyKey); const { descriptor, registration } = registerAndWrapFunction(target, propertyKey, inDescriptor); From 063002dea3c5c32b3b310abf334d7280b095f485 Mon Sep 17 00:00:00 2001 From: manojdbos Date: Thu, 9 Jan 2025 08:37:06 -0800 Subject: [PATCH 5/9] update template --- .../templates/hello-nextjs/src/actions/dbosWorkflow.tsx | 4 +++- src/dbos-executor.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx b/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx index 8900c422a..69ed4465d 100644 --- a/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx +++ b/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx @@ -45,7 +45,9 @@ class dbosWorkflowClass { // This code needs to execute at least once to launch the DBOS runtime // Do not delete this code if (process.env.NEXT_PHASE !== "phase-production-build") { - await DBOS.launch(); + // await DBOS.launch(); + await.DBOS.register(dbosWorkflowClass); + await } // The exported function is the entry point for the workflow diff --git a/src/dbos-executor.ts b/src/dbos-executor.ts index fbe72b5ac..9bcb090ea 100644 --- a/src/dbos-executor.ts +++ b/src/dbos-executor.ts @@ -549,7 +549,8 @@ export class DBOSExecutor implements DBOSExecutorContext { } const wfn = ro.className + '.' + ro.name; if (this.workflowInfoMap.has(wfn)) { - throw new DBOSError(`Repeated workflow name: ${wfn}`); + return + // throw new DBOSError(`Repeated workflow name: ${wfn}`); } const workflowInfo: WorkflowRegInfo = { workflow: wf, @@ -585,7 +586,8 @@ export class DBOSExecutor implements DBOSExecutorContext { const comm = ro.registeredFunction as StepFunction; const cfn = ro.className + '.' + ro.name; if (this.stepInfoMap.has(cfn)) { - throw new DBOSError(`Repeated Commmunicator name: ${cfn}`); + // throw new DBOSError(`Repeated Commmunicator name: ${cfn}`); + return } const stepInfo: StepRegInfo = { step: comm, @@ -601,7 +603,8 @@ export class DBOSExecutor implements DBOSExecutorContext { const cfn = ro.className + '.' + ro.name; if (this.procedureInfoMap.has(cfn)) { - throw new DBOSError(`Repeated Procedure name: ${cfn}`); + return + // throw new DBOSError(`Repeated Procedure name: ${cfn}`); } const procInfo: ProcedureRegInfo = { procedure: proc, From ef83cccfdcad75b0b9d7c263650d32f57c7ba7d3 Mon Sep 17 00:00:00 2001 From: manojdbos Date: Thu, 9 Jan 2025 10:33:01 -0800 Subject: [PATCH 6/9] clean up --- src/dbos-executor.ts | 29 ----------------------------- src/dbos.ts | 11 ----------- src/decorators.ts | 38 +------------------------------------- 3 files changed, 1 insertion(+), 77 deletions(-) diff --git a/src/dbos-executor.ts b/src/dbos-executor.ts index 9bcb090ea..0b0698947 100644 --- a/src/dbos-executor.ts +++ b/src/dbos-executor.ts @@ -184,7 +184,6 @@ export class DBOSExecutor implements DBOSExecutorContext { constructor(readonly config: DBOSConfig, systemDatabase?: SystemDatabase) { this.debugMode = config.debugMode ?? false; this.debugProxy = config.debugProxy; - console.log("start DBOSExecutor constructor") // Set configured environment variables if (config.env) { @@ -243,7 +242,6 @@ export class DBOSExecutor implements DBOSExecutorContext { this.initialized = false; DBOSExecutor.globalInstance = this; - console.log("exit DBOSExecutor constructor") } configureDbClient() { @@ -317,29 +315,21 @@ export class DBOSExecutor implements DBOSExecutorContext { registerClass(className: string) { - console.log("DBOSExecutor Registering class", className) - const cls = getRegisteredClassByName(className); if (cls === undefined) { throw new DBOSError(`Class ${className} not found`); } - // this.#registerClass(cls); this.#registerClass(cls.ctor); - - // cls.regComplete = true; } #registerClass(cls: object) { - console.log("#Registering class", cls) - const registeredClassOperations = getRegisteredOperations(cls); - // console.log("registeredClassOperations", registeredClassOperations) this.registeredOperations.push(...registeredClassOperations); for (const ro of registeredClassOperations) { if (ro.workflowConfig) { @@ -369,24 +359,13 @@ export class DBOSExecutor implements DBOSExecutorContext { } async init(classes?: object[]): Promise { - console.log("DbosExecutor init") if (this.initialized) { - /* this.logger.error("Workflow executor already initialized!"); - if (!classes || !classes.length) { - classes = getAllRegisteredClasses(); - console.log("registered Classes", classes) - } - for (const cls of classes) { - console.log("Registering class", cls) - this.#registerClass(cls); - } */ this.logger.error("Workflow executor already initialized!"); return; } if (!classes || !classes.length) { classes = getAllRegisteredClasses(); - console.log("registered Classes", classes) } type AnyConstructor = new (...args: unknown[]) => object; @@ -418,7 +397,6 @@ export class DBOSExecutor implements DBOSExecutorContext { } for (const cls of classes) { - console.log("Registering class", cls) this.#registerClass(cls); } @@ -541,8 +519,6 @@ export class DBOSExecutor implements DBOSExecutorContext { #registerWorkflow(ro: MethodRegistrationBase) { - console.log("registering workflow") - const wf = ro.registeredFunction as Workflow; if (wf.name === DBOSExecutor.tempWorkflowName) { throw new DBOSError(`Unexpected use of reserved workflow name: ${wf.name}`); @@ -550,7 +526,6 @@ export class DBOSExecutor implements DBOSExecutorContext { const wfn = ro.className + '.' + ro.name; if (this.workflowInfoMap.has(wfn)) { return - // throw new DBOSError(`Repeated workflow name: ${wfn}`); } const workflowInfo: WorkflowRegInfo = { workflow: wf, @@ -563,14 +538,10 @@ export class DBOSExecutor implements DBOSExecutorContext { #registerTransaction(ro: MethodRegistrationBase) { - console.log("registering transaction") - const txf = ro.registeredFunction as Transaction; const tfn = ro.className + '.' + ro.name; if (this.transactionInfoMap.has(tfn)) { - // throw new DBOSError(`Repeated Transaction name: ${tfn}`); - console.log(`Repeated Transaction name: ${tfn}`); return; } const txnInfo: TransactionRegInfo = { diff --git a/src/dbos.ts b/src/dbos.ts index 988789366..55ccbda4d 100644 --- a/src/dbos.ts +++ b/src/dbos.ts @@ -149,14 +149,11 @@ export class DBOS { static async register(cls: any) { - console.log("DBOS.register class: ", cls.name); - await this.launch(); const executor = DBOSExecutor.globalInstance; if (executor !== undefined) { - // executor.registerClass(cls.mjclassName); executor.registerClass(cls.name) } else { throw new DBOSExecutorNotInitializedError(); @@ -167,13 +164,9 @@ export class DBOS { static async launch(httpApps?: DBOSHttpApps) { // Do nothing is DBOS is already initialized if (DBOSExecutor.globalInstance) { - // console.log("DBOS already initialized. But running init again"); - // DBOSExecutor.globalInstance.init(); return } - console.log("Launching DBOS.launch()"); - // Initialize the DBOS executor if (!DBOS.dbosConfig) { const [dbosConfig, runtimeConfig]: [DBOSConfig, DBOSRuntimeConfig] = parseConfigFile(); @@ -839,10 +832,6 @@ export class DBOS { inDescriptor: TypedPropertyDescriptor<(this: This, ...args: Args) => Promise>) { - console.log("mjjjj Transaction decorator called"); - - - const { descriptor, registration } = registerAndWrapContextFreeFunction(target, propertyKey, inDescriptor); registration.txnConfig = config; diff --git a/src/decorators.ts b/src/decorators.ts index 4492cd534..ff23e878c 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -260,25 +260,15 @@ export function registerFunctionWrapper(func: unknown, reg: MethodRegistration { const registeredOperations: MethodRegistrationBase[] = []; - - - // const clname = (target as any).mjclassName - - // console.log("We are in getRegisteredOperations", clname) - if (typeof target === 'function') { // Constructor case const classReg = classesByName.get(target.name); - // const classReg = classesByName.get(clname); - console.log("function classReg", classReg) classReg?.registeredOperations?.forEach((m) =>registeredOperations.push(m)); } else { let current: object | undefined = target; while (current) { const cname = current.constructor.name; - // const cname = clname; - console.log("not a function classReg", cname, classesByName) if (classesByName.has(cname)) { registeredOperations.push(...getRegisteredOperations(current.constructor)); } @@ -467,11 +457,7 @@ export function registerAndWrapContextFreeFunction(ctor)); - console.log("Done Inserting class registration", name); - } - console.log("after number of regis", classesByName.size); const clsReg: ClassRegistration = classesByName.get(name)!; if (clsReg.needsInitialized) { @@ -623,14 +598,12 @@ export function DefaultArgRequired(ctor: T) { - console.log("We are in DefaultArgOptional", ctor.name); const clsreg = getOrCreateClassRegistration(ctor); clsreg.defaultArgRequired = ArgRequiredOptions.OPTIONAL; } export function configureInstance(cls: new (name:string, ...args: T) => R, name: string, ...args: T) : R { - console.log("We are in configureInstance", cls.name, name); const inst = new cls(name, ...args); const creg = getOrCreateClassRegistration(cls as new(...args: unknown[])=>R); if (creg.configuredInstances.has(name)) { @@ -678,15 +651,6 @@ export function Transaction(config: TransactionConfig={}) { // eslint-disable-next-line @typescript-eslint/no-explicit-any inDescriptor: TypedPropertyDescriptor<(this: This, ctx: TransactionContext, ...args: Args) => Promise>) { - - console.log("mjjjj We are in Transaction decorator", target, propertyKey, inDescriptor); - const xxxName = Reflect.getMetadata('design:type', target)?.name ?? 'UnknownClass'; - - console.log(`Transaction decorator applied to: ${xxxName}.${propertyKey}`); - - - const className = (target as any).constructor.mjclassName; - console.log("In Transaction decorator Class Name:", className, propertyKey); const { descriptor, registration } = registerAndWrapFunction(target, propertyKey, inDescriptor); registration.txnConfig = config; return descriptor; From ec16446615775bbcb00683c4f257d21ba1a11a9a Mon Sep 17 00:00:00 2001 From: manojdbos Date: Thu, 9 Jan 2025 10:35:53 -0800 Subject: [PATCH 7/9] fix typo --- .../templates/hello-nextjs/src/actions/dbosWorkflow.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx b/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx index 69ed4465d..85f31b066 100644 --- a/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx +++ b/packages/create/templates/hello-nextjs/src/actions/dbosWorkflow.tsx @@ -45,9 +45,8 @@ class dbosWorkflowClass { // This code needs to execute at least once to launch the DBOS runtime // Do not delete this code if (process.env.NEXT_PHASE !== "phase-production-build") { - // await DBOS.launch(); - await.DBOS.register(dbosWorkflowClass); - await + await DBOS.register(dbosWorkflowClass); + } // The exported function is the entry point for the workflow From 8f0bd727989107ab17910eea36dde1947d7c0be6 Mon Sep 17 00:00:00 2001 From: manojdbos Date: Thu, 9 Jan 2025 10:46:51 -0800 Subject: [PATCH 8/9] clean up --- src/dbos-executor.ts | 6 ------ src/dbos.ts | 1 - src/decorators.ts | 12 ++---------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/dbos-executor.ts b/src/dbos-executor.ts index 0b0698947..a3eaf9c8b 100644 --- a/src/dbos-executor.ts +++ b/src/dbos-executor.ts @@ -241,7 +241,6 @@ export class DBOSExecutor implements DBOSExecutorContext { this.initialized = false; DBOSExecutor.globalInstance = this; - } configureDbClient() { @@ -325,10 +324,7 @@ export class DBOSExecutor implements DBOSExecutorContext { } - #registerClass(cls: object) { - - const registeredClassOperations = getRegisteredOperations(cls); this.registeredOperations.push(...registeredClassOperations); for (const ro of registeredClassOperations) { @@ -557,7 +553,6 @@ export class DBOSExecutor implements DBOSExecutorContext { const comm = ro.registeredFunction as StepFunction; const cfn = ro.className + '.' + ro.name; if (this.stepInfoMap.has(cfn)) { - // throw new DBOSError(`Repeated Commmunicator name: ${cfn}`); return } const stepInfo: StepRegInfo = { @@ -575,7 +570,6 @@ export class DBOSExecutor implements DBOSExecutorContext { if (this.procedureInfoMap.has(cfn)) { return - // throw new DBOSError(`Repeated Procedure name: ${cfn}`); } const procInfo: ProcedureRegInfo = { procedure: proc, diff --git a/src/dbos.ts b/src/dbos.ts index 55ccbda4d..44a0ee1b6 100644 --- a/src/dbos.ts +++ b/src/dbos.ts @@ -831,7 +831,6 @@ export class DBOS { propertyKey: string, inDescriptor: TypedPropertyDescriptor<(this: This, ...args: Args) => Promise>) { - const { descriptor, registration } = registerAndWrapContextFreeFunction(target, propertyKey, inDescriptor); registration.txnConfig = config; diff --git a/src/decorators.ts b/src/decorators.ts index ff23e878c..b99f2876f 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -260,7 +260,6 @@ export function registerFunctionWrapper(func: unknown, reg: MethodRegistration { const registeredOperations: MethodRegistrationBase[] = []; - if (typeof target === 'function') { // Constructor case const classReg = classesByName.get(target.name); classReg?.registeredOperations?.forEach((m) =>registeredOperations.push(m)); @@ -335,7 +334,7 @@ function getOrCreateMethodRegistration( isInstance = true; } - const classReg = getOrCreateClassRegistration(regtarget, propertyKey); + const classReg = getOrCreateClassRegistration(regtarget); const fname = propertyKey.toString(); if (!classReg.registeredOperations.has(fname)) { @@ -446,9 +445,7 @@ export function registerAndWrapFunction(ta throw Error("Use of decorator when original method is undefined"); } - const registration = getOrCreateMethodRegistration(target, propertyKey, descriptor, true); - return { descriptor, registration }; } @@ -456,7 +453,6 @@ export function registerAndWrapContextFreeFunction( - ctor: CT, propertyKey?: string | symbol + ctor: CT ) { - const name = ctor.name; - if (!classesByName.has(name)) { classesByName.set(name, new ClassRegistration(ctor)); } - const clsReg: ClassRegistration = classesByName.get(name)!; - if (clsReg.needsInitialized) { clsReg.name = name; clsReg.needsInitialized = false; From a7ec63e3546e49c385cda3b78847c273c8d65b95 Mon Sep 17 00:00:00 2001 From: manojdbos Date: Thu, 9 Jan 2025 11:09:23 -0800 Subject: [PATCH 9/9] fix lint error --- src/dbos.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dbos.ts b/src/dbos.ts index 44a0ee1b6..ae3123128 100644 --- a/src/dbos.ts +++ b/src/dbos.ts @@ -147,6 +147,7 @@ export class DBOS { set(conf, key, newValue); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any static async register(cls: any) { await this.launch(); @@ -154,6 +155,7 @@ export class DBOS { const executor = DBOSExecutor.globalInstance; if (executor !== undefined) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access executor.registerClass(cls.name) } else { throw new DBOSExecutorNotInitializedError();