Hi @icebob, as we talk, here is the repository:
https://github.com/tinchoz49/example-moleculer-wait-for-services
Thank you!
@tinchoz49 I checked it. If you return with the waitForServices in started, it will cause a dead lock, because transporter wait for all local services started, but the service wait for receive other services via transporter. Workaround is to remove the return in started. But I will think out something to solve it.
maybe we can define a hook method started or like an option waitForServices in the moleculer.config.js to hook up in the broker.start() promise.
Something like this:
// moleculer.config.js
module.exports = {
namespace: 'dev',
nodeID: 'node-' + process.pid,
waitForServices: ['greeter-two'],
...
};
@tinchoz49 I'd sugest something like dependencies or depends_on instead of waitForServices in this case
I vote to dependencies but it would be better to place it into the service schema because every service has different dependencies.
Example:
// posts.service.js
module.exports = {
name: "posts",
dependencies: ["users", "comments"]
....
}
In this case the broker will call the "posts" service started handler if all dependent services are available.
What do you think?
I like the suggestion! my vote for dependencies at the service schema level.
It doesn't make sense to fire started if dependencies are still pending, so yeah, that works. :)
I'm just wondering if theres interdependent services, for example A <-> B. This scenario will be blocked (if publishing to the network depends on started callback), yet, you can't accept calls if started wasn't called, because some initialization might be pending.
After #112 it should support versioned services too. And need an internal settings for timeout:
// posts.service.js
module.exports = {
name: "posts",
settings: {
$dependencyTimeout: 30000
},
dependencies: [
"likes", // shorthand w/o version
{ name: "users", version: 2 }, // with numeric version
{ name: "comments", version: "staging" } // with string version
]
....
}
Default value of $dependencyTimeout is 0 - no timeout
Done. Will be released in v0.11.2 (this week)
thanks for making each day this library more awesome!
Released in v0.11.2
Most helpful comment
thanks for making each day this library more awesome!