Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple dbos app files in NextJs App #700

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
debug statements
  • Loading branch information
manojdbos committed Jan 3, 2025
commit bfd8280dea73323887770f9c24e18ec48a9711f1
15 changes: 15 additions & 0 deletions src/dbos-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -241,6 +242,8 @@ export class DBOSExecutor implements DBOSExecutorContext {

this.initialized = false;
DBOSExecutor.globalInstance = this;

console.log("exit DBOSExecutor constructor")
}

configureDbClient() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -343,13 +349,15 @@ export class DBOSExecutor implements DBOSExecutorContext {
}

async init(classes?: object[]): Promise<void> {
console.log("DbosExecutor init")
if (this.initialized) {
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;
Expand Down Expand Up @@ -381,6 +389,7 @@ export class DBOSExecutor implements DBOSExecutorContext {
}

for (const cls of classes) {
console.log("Registering class", cls)
this.#registerClass(cls);
}

Expand Down Expand Up @@ -502,6 +511,9 @@ export class DBOSExecutor implements DBOSExecutorContext {
/* WORKFLOW OPERATIONS */

#registerWorkflow(ro: MethodRegistrationBase) {

console.log("registering workflow")

const wf = ro.registeredFunction as Workflow<unknown[], unknown>;
if (wf.name === DBOSExecutor.tempWorkflowName) {
throw new DBOSError(`Unexpected use of reserved workflow name: ${wf.name}`);
Expand All @@ -520,6 +532,9 @@ export class DBOSExecutor implements DBOSExecutorContext {
}

#registerTransaction(ro: MethodRegistrationBase) {

console.log("registering transaction")

const txf = ro.registeredFunction as Transaction<unknown[], unknown>;
const tfn = ro.className + '.' + ro.name;

Expand Down
2 changes: 2 additions & 0 deletions src/dbos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ export function registerAndWrapContextFreeFunction<This, Args extends unknown[],
throw Error("Use of decorator when original method is undefined");
}

console.log("mjjjj We are in registerAndWrapContextFreeFunction", target.constructor.name, target, propertyKey);
const registration = getOrCreateMethodRegistration(target, propertyKey, descriptor, false);

return { descriptor, registration };
Expand All @@ -464,6 +465,8 @@ type AnyConstructor = new (...args: unknown[]) => object;
const classesByName: Map<string, ClassRegistration<AnyConstructor> > = 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);
Expand All @@ -474,9 +477,19 @@ export function getAllRegisteredClasses() {
export function getOrCreateClassRegistration<CT extends { new (...args: unknown[]) : object }>(
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<CT>(ctor));
console.log("Done Inserting class registration", name);

}
const clsReg: ClassRegistration<AnyConstructor> = classesByName.get(name)!;

Expand Down Expand Up @@ -590,12 +603,14 @@ export function DefaultArgRequired<T extends { new (...args: unknown[]) : object

export function DefaultArgOptional<T extends { new (...args: unknown[]) : object }>(ctor: T)
{
console.log("We are in DefaultArgOptional", ctor.name);
const clsreg = getOrCreateClassRegistration(ctor);
clsreg.defaultArgRequired = ArgRequiredOptions.OPTIONAL;
}

export function configureInstance<R extends ConfiguredInstance, T extends unknown[]>(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)) {
Expand Down