Skip to content

Commit 9d6dbbd

Browse files
committed
Add logs
1 parent 9397c15 commit 9d6dbbd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/sequencer/src/sequencer/executor/Sequencer.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ export class Sequencer<Modules extends SequencerModulesRecord>
6666
* modules to start each
6767
*/
6868
public async start() {
69+
// The sequencer uses Tysringe to resolve modules (and their dependencies)
70+
// and then starts them. However, this can be problematic as although Tysringe may resolve
71+
// dependencies, it doesn't actually start them. For example, a database may be created,
72+
// but the connection strings, etc, won't be constructed until it's started, and this may
73+
// cause an error if a module that relies on it is started first. The way to fix this is
74+
// ensure that we start modules based on the order they were resolved.
75+
// We iterate through the methods three times:
76+
6977
this.useDependencyFactory(this.container.resolve(MethodIdFactory));
7078

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

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

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

0 commit comments

Comments
 (0)