feat(payload-cloud): set up cron jobs on init#10106
Conversation
|
No dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No dependency changes detected in pull request |
DanRibbens
left a comment
There was a problem hiding this comment.
What are your thoughts?
|
|
||
| function waitRandomTime(): Promise<void> { | ||
| const min = 1000 // 1 second in milliseconds | ||
| const max = 5000 // 5 seconds in milliseconds |
There was a problem hiding this comment.
The window of time does not seem long enough to gaurentee that multiple instances aren't self identifying as the cron runner.
A min of 1 second between starting up the app instance, connecting to the database, and updating the global all adds up to a much larger tolerance needed if I had to guess.
I'm not sure how much you'ved tested this, but to me we should remove the waitRandomTime() entirely and just let the instances write their unique id to the global as they all come up. Then in a setTimeout with 2 full minutes do lines 140 - 155.
| /** | ||
| * Queue cron jobs automatically on payload initialization. | ||
| * @remark this property should not be used on serverless platforms like Vercel | ||
| */ | ||
| autoRun?: ((payload: Payload) => CronConfig[] | Promise<CronConfig[]>) | CronConfig[] |
There was a problem hiding this comment.
same as the comment above. This is from the other PR... ¿¿???
| const DEFAULT_CRON = '* * * * *' | ||
| const DEFAULT_LIMIT = 10 | ||
| const DEFAULT_CRON_JOB = { | ||
| cron: DEFAULT_CRON, | ||
| limit: DEFAULT_LIMIT, | ||
| queue: 'default (every minute)', |
There was a problem hiding this comment.
Now that cronjobs are defined in config.jobs.autoRun and not in the plugin, where this "default cron job" should be documented. I copy the internal question:
Should the default cronjob:
- be set always after jobs.autoRun if it returns an empty array []?
- be set only in Payload Cloud Plugin if jobs autoRun returns an empty array?
- there should not be a default cronjob.
Personally I like option 3 better.
If we go with option 2 where would it be documented in tsdoc? the payload cloud plugin will not have any option to configure cron jobs, just to enable or disable it
|
🚀 This is included in version v3.16.0 |
If the user has tasks configured, we set up cron jobs on init. We also make sure to only run on one instance using a instance identifier stored in a global. This adds a new property to the payloadCloudPlugin: `jobs`.
If the user has tasks configured, we set up cron jobs on init.
We also make sure to only run on one instance using a instance identifier stored in a global.
This adds a new property to the payloadCloudPlugin:
jobs.