You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
@Injectable()
export class TestCron {
private readonly logger = new Logger(TestCron.name);
@Cron('45 * * * * *')
handleCron() {
this.logger.debug('Called when the current second is 45');
}
}
But I get the following error
(node:20320) UnhandledPromiseRejectionWarning: TypeError: cron_1.CronJob is not a constructor
at ...\node_modules\@nestjs\schedule\dist\scheduler.orchestrator.js:58:29
Expected behavior
No error should be thrown. In fact if I use @Interval instead of @Cron it works as expected:
@Interval(1000)
handleCron() {
this.logger.debug('Called when the current second is 45');
}
[Nest] 23620 - 2020-01-03 14:35:18 [TestCron] Called when the current second is 45
[Nest] 23620 - 2020-01-03 14:35:19 [TestCron] Called when the current second is 45
[Nest] 23620 - 2020-01-03 14:35:20 [TestCron] Called when the current second is 45
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
It turned out that the problem is not coming from the lib, but it is something that other people could run into so I will post a short explanation:
We use tsconfig-paths (https://www.npmjs.com/package/tsconfig-paths) to be able to use module paths relative to the project root. In the project root, however, we have a folder called cron where we keep a set ot cron classes that hold cron methods (as opposed to having cron methods in the service classes). All this classes are exported through a cron/index.ts file and imported as: import cron from 'cron'.
The lib, however, also uses a module called cron, and when it imports it the resolver imports our cron module instead of the proper dependency.
I'm submitting a...
Current behavior
By following the example here: https://docs.nestjs.com/techniques/task-scheduling I have code that looks like that:
But I get the following error
Expected behavior
No error should be thrown. In fact if I use
@Interval
instead of@Cron
it works as expected:Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: