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

add: new option for initial services dependencies #1318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GabrielButarelo
Copy link

📝 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

📜 Example code

const broker = new ServiceBroker({
    initialDependencies: ['databases-service']
});

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:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

@GabrielButarelo GabrielButarelo changed the title Add new option for initial services dependencies add: new option for initial services dependencies Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant