Skip to content

Commit

Permalink
Add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ejMina226 committed Dec 13, 2024
1 parent 9397c15 commit 9d6dbbd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/sequencer/src/sequencer/executor/Sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export class Sequencer<Modules extends SequencerModulesRecord>
* modules to start each
*/
public async start() {
// The sequencer uses Tysringe to resolve modules (and their dependencies)
// and then starts them. However, this can be problematic as although Tysringe may resolve
// dependencies, it doesn't actually start them. For example, a database may be created,
// but the connection strings, etc, won't be constructed until it's started, and this may
// cause an error if a module that relies on it is started first. The way to fix this is
// ensure that we start modules based on the order they were resolved.
// We iterate through the methods three times:

this.useDependencyFactory(this.container.resolve(MethodIdFactory));

// Log startup info
Expand All @@ -75,6 +83,8 @@ export class Sequencer<Modules extends SequencerModulesRecord>
log.info("Starting sequencer...");
log.info("Modules:", moduleClassNames);

// Iteration #1: We invoke the afterResolution feature for the container
// to ensure every time a module is resolved it gets recorded.
const orderedModules: Extract<keyof Modules, string>[] = [];
// eslint-disable-next-line guard-for-in
for (const moduleName in this.definition.modules) {
Expand All @@ -88,6 +98,8 @@ export class Sequencer<Modules extends SequencerModulesRecord>
}
);
}
// Iteration #2: We resolve each module and thus populate
// the orderedModules list to understand the sequencing.
// eslint-disable-next-line guard-for-in
for (const moduleName in this.definition.modules) {
const sequencerModule = this.resolve(moduleName);
Expand All @@ -96,6 +108,8 @@ export class Sequencer<Modules extends SequencerModulesRecord>
);
}

// Iteration #3: We now iterate though the orderedModules list
// and start the modules in the order they were resolved.
for (const moduleName of orderedModules) {
const sequencerModule = this.resolve(moduleName);
// eslint-disable-next-line no-await-in-loop
Expand Down

0 comments on commit 9d6dbbd

Please sign in to comment.