Skip to content

register all cron jobs in entrypoint #12791

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

Merged
merged 6 commits into from
Jun 23, 2025

Conversation

ehconitin
Copy link
Contributor

@ehconitin ehconitin commented Jun 23, 2025

closes twentyhq/core-team-issues#1113

Three things I am not sure about -

@ehconitin ehconitin requested a review from FelixMalfait June 23, 2025 14:05
@ehconitin ehconitin self-assigned this Jun 23, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added centralized cron job registration functionality in the server entrypoint, with new command and module exports to manage background sync jobs.

  • Command placement in database/commands is architecturally misaligned; consider moving to a dedicated cron or scheduler module given its distinct responsibility
  • Missing environment variable control (like DISABLE_CRON_JOBS_REGISTRATION) for different deployment scenarios
  • Error handling in entrypoint.sh could be improved to include specific error logging and proper cleanup of stale jobs
  • Consider race conditions where cron jobs might be registered before the database is fully ready
  • Added exports in multiple modules (MessagingImportManagerModule, CalendarEventImportManagerModule) should be documented for better maintainability

7 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

Comment on lines 32 to 40
register_background_jobs() {

echo "Registering background sync jobs..."
if yarn command:prod cron:register:all; then
echo "Successfully registered all background sync jobs!"
else
echo "Warning: Failed to register background jobs, but continuing startup..."
fi
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Similar to DISABLE_DB_MIGRATIONS, consider adding DISABLE_CRON_JOBS flag to control job registration behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

much better name than what I suggested in description :)

Copy link
Member

Choose a reason for hiding this comment

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

I actually prefer your name DISABLE_CRON_JOBS_REGISTRATION. And I think it would be a good idea to add this so that we can disable it in our cloud yes!

@@ -2,3 +2,4 @@
.env
node_modules
.nx/cache
packages/twenty-server/.env
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 took too long to figure this out but apparently the existing .env rule only ignores root-level files packages/twenty-server/.env was still being copied with localhost:5432, breaking container db connections

Copy link
Contributor

github-actions bot commented Jun 23, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:6612

This environment will automatically shut down when the PR is closed or after 5 hours.

}

async run(): Promise<void> {
this.logger.log('Registering all background sync cron jobs...');
Copy link
Member

Choose a reason for hiding this comment

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

In a couple weeks let's update the docs to emphasize on the admin panel to check everything is properly started and remove the part that tells the user to run this manually

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

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

Great!

@FelixMalfait FelixMalfait merged commit 6aee42a into twentyhq:main Jun 23, 2025
39 checks passed
Copy link
Contributor

Thanks @ehconitin for your contribution!
This marks your 153rd PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make cron jobs run automatically during setup
2 participants