add: new option for initial services dependencies #1318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Description
At the company where I work, we recently encountered a challenge with MoleculerJS. We needed to initialize a service responsible for managing database connections before all the other services we have built (which currently number in the hundreds). The solution we found was to add the dependencies field to the schema of every service, referencing the name of the service we wanted the others to wait for. This led to the development of an improvement where we can pass the --dependencies option in the runner, specifying the names of the services that all other services should wait for to load. Alternatively, we can simply add them to the initialDependencies array in the broker.
🎯 Relevant issues
N/A
💎 Type of change
📜 Example code
ts-node ./node_modules/moleculer/bin/moleculer-runner.js --hot --repl --config moleculer.config.ts services/**/*.services.ts --dependencies databases-service
🚦 How Has This Been Tested?
To test it, simply create two services and set one as a dependency. If you're using the runner, you can pass the --dependencies option. If you're manually instantiating the broker, you can use the initialDependencies option in the settings. Run the program and check if it waits for the dependent service to start before starting the other.
🏁 Checklist: