Please answer the following questions for yourself before submitting an issue.
I've created a service user that on the started lifecycle callback calls a few action of the same service through the broker. When I try to do that a SERVICE_NOT_FOUND exception is thrown.
I'm expecting that calling an action in the started callback of the service itself wouldn't be a problem.
Exception: ServiceNotFoundError: Service 'user.register' is not found.
module.exports = {
name: 'user',
actions: {
myAction(ctx) {
return Promise.resolve();
}
},
methods: {
_myMethod() {
// throwing error here! user.myAction not registered
return this.broker.call('user.myAction');
}
},
started() {
return this._myMethod();
}
};
Calling the action with a delay through setTimeout.
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
It's not available because while the service is not started properly, it doesn't appear in the Service Registry, so you can't call. You can't call a not started service. If you want to call an own service from started, use the this.actions.myAction() form.
Ok that's fine... Actually I had too much dependencies for the action I wanted to call so I made a bootstrap script inside the started of the broker. In that case I should be sure that all services are correctly initialized and register, shouldn't I?
I'll close this, but first I was wondering there is no lifecycle method in a service that achives my purpose?
You can subscribe to the $broker.started event:
module.exports = {
name: "posts",
events: {
"$broker.started"() {
// All local services started.
}
}
};
That's great, thank you!