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

Service dependencies option #102

Closed
tinchoz49 opened this issue Sep 18, 2017 · 11 comments
Closed

Service dependencies option #102

tinchoz49 opened this issue Sep 18, 2017 · 11 comments

Comments

@tinchoz49
Copy link
Contributor

tinchoz49 commented Sep 18, 2017

Hi @icebob, as we talk, here is the repository:

https://github.com/tinchoz49/example-moleculer-wait-for-services

@icebob
Copy link
Member

icebob commented Sep 18, 2017

Thank you!

@icebob
Copy link
Member

icebob commented Sep 19, 2017

@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.

@tinchoz49
Copy link
Contributor Author

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'],
  ...
};

@WoLfulus
Copy link
Contributor

@tinchoz49 I'd sugest something like dependencies or depends_on instead of waitForServices in this case

@icebob
Copy link
Member

icebob commented Sep 20, 2017

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?

@tinchoz49
Copy link
Contributor Author

I like the suggestion! my vote for dependencies at the service schema level.

@WoLfulus
Copy link
Contributor

WoLfulus commented Sep 20, 2017

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.

@icebob icebob changed the title Test waitForServices in started method Service dependencies option Sep 22, 2017
@icebob
Copy link
Member

icebob commented Oct 1, 2017

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

@icebob
Copy link
Member

icebob commented Oct 2, 2017

Done. Will be released in v0.11.2 (this week)

@icebob icebob closed this as completed Oct 2, 2017
@tinchoz49
Copy link
Contributor Author

thanks for making each day this library more awesome!

@icebob
Copy link
Member

icebob commented Oct 6, 2017

Released in v0.11.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants