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

feat(@nestjs/scheduler): Add a warning when using non static providers #726

Merged
merged 1 commit into from Nov 16, 2021
Merged

feat(@nestjs/scheduler): Add a warning when using non static providers #726

merged 1 commit into from Nov 16, 2021

Conversation

jshayes
Copy link
Contributor

@jshayes jshayes commented Nov 15, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Currently when registering a request scoped provider that defines cron jobs, it does not register the cron jobs. This is because it filters out non static providers. In addition to this, there are not warning logs, making this less obvious as to why the cron jobs are not being registered.

What is the new behavior?

It behaves the same way as before except it will now log a warning when using a request scoped provider.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

In our cron jobs we emit events over nats. We had an issue come up recently where the nats client was updated to become request scoped. This resulted in our cron jobs breaking since it does not register cron jobs for request scoped providers. There were also no warning logs associated with this, so it was not immediately obvious why the cron jobs stopped working. This adds some warning logs to make this issue easier to debug in the future.

Adds a warning when trying to register cron jobs/timeouts/intervals using a non static provider.
);
});
instanceWrappers.forEach((wrapper: InstanceWrapper) => {
const { instance } = wrapper;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure the implication of getting an instance for a request scoped provider here. It seems like it uses a static context id when resolving the instance, but I do not know if this could cause any issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine! For request-scoped providers, instance would be a prototype object

@kamilmysliwiec kamilmysliwiec merged commit 85f3c0e into nestjs:master Nov 16, 2021
@kamilmysliwiec
Copy link
Member

This is great @jshayes, thank you! 🙌

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.

None yet

2 participants