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

update bootstrap.js adding check endaoment #1905

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Jan 13, 2025

Summary by CodeRabbit

  • New Features
    • Added a new cron job to periodically check and update Endaoment projects.
    • Introduced a cron job for generating a sitemap, configurable via environment settings.

@kkatusic kkatusic self-assigned this Jan 13, 2025
@kkatusic kkatusic requested a review from CarlosQ96 January 13, 2025 17:24
Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Walkthrough

The pull request introduces new cron job functionality by adding two functions: runCheckAndUpdateEndaomentProject and runGenerateSitemapOnFrontend. The first function is integrated into the initializeCronJobs function, enabling periodic checks and updates of Endaoment projects. The second function is conditionally invoked based on the SITEMAP_CRON_SECRET environment variable and retrieves its scheduling expression from the configuration. This enhances the application's automated task management capabilities without altering existing logic.

Changes

File Change Summary
src/server/bootstrap.ts Added imports for runCheckAndUpdateEndaomentProject and runGenerateSitemapOnFrontend, included them in initializeCronJobs
src/services/cronJobs/generateSitemapOnFrontend.ts Introduced import for config, modified cron job declaration to use GENERATE_SITEMAP_CRONJOB_EXPRESSION, with a default fallback

Possibly related PRs

Suggested reviewers

  • CarlosQ96

Poem

🐰 In the code where cron jobs play,
New functions hop in, brightening the day.
Endaoment checks, sitemaps in line,
Automation's magic, all works just fine!
Hopping through tasks, with joy we delight! 🕰️

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d61941 and acd0e5d.

📒 Files selected for processing (1)
  • src/server/bootstrap.ts (2 hunks)
🔇 Additional comments (1)
src/server/bootstrap.ts (1)

74-74: LGTM!

The import follows the established pattern for cron job imports.

Let's verify the imported function exists and follows the cron job pattern:

✅ Verification successful

Implementation verified - follows all best practices

The imported function is properly implemented with:

  • Configurable schedule via CHECK_AND_UPDATE_ENDAOMENT_PROJECTS_CRONJOB_EXPRESSION
  • Comprehensive error handling and logging
  • Proper cron job scheduling pattern
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the imported cron job function exists and follows the pattern
# Test: Check if the function exists and follows cron job patterns
ast-grep --pattern $'export function runCheckAndUpdateEndaomentProject() {
  $$$
}'

Length of output: 84


Script:

#!/bin/bash
# First, locate the file
fd "checkAndUpdateEndaomentProject.ts"

# Try a more flexible pattern match
ast-grep --pattern 'export function runCheckAndUpdateEndaomentProject'

# Fallback to text search
rg "runCheckAndUpdateEndaomentProject" -l

Length of output: 289


Script:

#!/bin/bash
# View the implementation
cat src/services/cronJobs/checkAndUpdateEndaomentProject.ts

# Look for related environment variables
rg "ENDAOMENT" --type env

Length of output: 3101

src/server/bootstrap.ts Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/services/cronJobs/generateSitemapOnFrontend.ts (1)

Line range hint 28-34: Fix template literal syntax errors in the axios request.

The URL and Authorization header use incorrect template literal syntax that would cause runtime errors.

Apply this diff to fix the syntax:

-        `{process.env.FRONTEND_URL}/api/generate-sitemap`,
+        `${process.env.FRONTEND_URL}/api/generate-sitemap`,
         {
           headers: {
-            Authorization: `Bearer {process.env.SITEMAP_CRON_SECRET}`,
+            Authorization: `Bearer ${process.env.SITEMAP_CRON_SECRET}`,
           },
         },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between acd0e5d and e9ea066.

📒 Files selected for processing (2)
  • src/server/bootstrap.ts (3 hunks)
  • src/services/cronJobs/generateSitemapOnFrontend.ts (1 hunks)
🔇 Additional comments (2)
src/services/cronJobs/generateSitemapOnFrontend.ts (1)

15-17: LGTM! Well-implemented configurable cron schedule.

The implementation properly retrieves the cron schedule from config with a sensible fallback to run every Sunday at midnight.

src/server/bootstrap.ts (1)

367-367: Add environment variable control for the Endaoment cron job.

The cron job lacks environment variable control for enabling/disabling, making it harder to control in different environments.

Comment on lines +382 to +384
if (process.env.SITEMAP_CRON_SECRET !== '') {
runGenerateSitemapOnFrontend();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve the environment variable check for the sitemap cron job.

The current check !== '' is not a robust way to verify environment variables. It would treat 'false' or '0' as valid values.

Apply this diff to implement a more robust check:

-    if (process.env.SITEMAP_CRON_SECRET !== '') {
+    if (process.env.SITEMAP_CRON_SECRET && process.env.ENABLE_SITEMAP_CRON === 'true') {
       runGenerateSitemapOnFrontend();
     }

This change:

  1. Ensures the secret exists
  2. Adds explicit control via ENABLE_SITEMAP_CRON
  3. Follows the codebase pattern of using === 'true' for feature flags
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (process.env.SITEMAP_CRON_SECRET !== '') {
runGenerateSitemapOnFrontend();
}
if (process.env.SITEMAP_CRON_SECRET && process.env.ENABLE_SITEMAP_CRON === 'true') {
runGenerateSitemapOnFrontend();
}

@kkatusic kkatusic merged commit e8a7de5 into staging Jan 13, 2025
5 checks passed
@kkatusic kkatusic deleted the feat/check_periodically_endaoment branch January 13, 2025 19:08
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.

2 participants