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

Created and Started hooks are not called. #22

Closed
Anruin opened this issue May 30, 2020 · 2 comments
Closed

Created and Started hooks are not called. #22

Anruin opened this issue May 30, 2020 · 2 comments

Comments

@Anruin
Copy link

Anruin commented May 30, 2020

Greetings.
I'm using the "dev" configuration from the package.json (using moleculer-runner) using Moleculer version 0.13.13 (TypeScript). I have the following code in moleculer.config.ts (excerpt):

...
created: async (broker: ServiceBroker) => {
    broker.logger.error("CREATED");
},

started: async (broker: ServiceBroker) => {
    broker.logger.error("STARTED");
},
...

Except of adding these functions I also added NATS configuration of 3 options, and it works.

When I run npm run dev, these functions are not called, and I don't see those messages (and any other code there won't run).

Debugging through the code led me to the node_modules/moleculer/src/service-broker.js@348, where I can see this code:

...
.then(() => {
	if (_.isFunction(this.options.started))
		return this.options.started(this);
});

Under debugger it says that this.options.started is undefined, while this.options.brokerConfig includes this "started" event (and "created" as well).

When I run it without moleculer-runner, e.g. using jest in tests, creating broker with const broker = new ServiceBroker(brokerConfig);, these methods are there and they are being called and run.

How to make it call these "created" and "started" events on the broker using moleculer-runner? Thank you.

@Anruin
Copy link
Author

Anruin commented May 30, 2020

OK, I figured it out.
I have changed module.exports to export const, and that led to this error.
Now I had to change the import in my tests to this:
const brokerConfig = require("../../moleculer.config");
But linter does not like mixing imports and requires.

@Anruin
Copy link
Author

Anruin commented Jun 1, 2020

Fixed it like this: import brokerConfig = require("../../moleculer.config");

@Anruin Anruin closed this as completed Jun 1, 2020
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

No branches or pull requests

1 participant