Skip to content

Using @nestjs/schedule module #2464

Answered by michaelbromley
lupeaserban asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

Yes, just using the Cron decorator is not suitable for multiple instances. I discuss that in this thread, and long-term I would like to support scheduled tasks in a more native way.

Your solution is fine, although the way you do it there will replace all the plugins with just the CronPlugin, which might not be what you want. From the docs:

Arrays do not get merged, they are treated as a single value that will be replaced. So if merging the plugins array, you must explicitly concatenate the array.

So you'd want it like:

const workerConfig = mergeConfig(config, { plugins: [...config.plugins, CronPlugin], }); 

What if i want to register the plugin only on the main app and not having i…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lupeaserban
Comment options

Answer selected by lupeaserban
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants