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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import { runCheckPendingUserModelScoreCronjob } from '../services/cronJobs/syncU
import { isTestEnv } from '../utils/utils';
import { refreshProjectEstimatedMatchingView } from '../services/projectViewsService';
import { runSyncEstimatedClusterMatchingCronjob } from '../services/cronJobs/syncEstimatedClusterMatchingJob';
import { runCheckAndUpdateEndaomentProject } from '../services/cronJobs/checkAndUpdateEndaomentProject';
import { runGenerateSitemapOnFrontend } from '../services/cronJobs/generateSitemapOnFrontend';

Resource.validate = validate;

Expand Down Expand Up @@ -362,6 +364,7 @@ export async function bootstrap() {
runCheckPendingRecurringDonationsCronJob();
runNotifyMissingDonationsCronJob();
runCheckPendingProjectListingCronJob();
runCheckAndUpdateEndaomentProject();
kkatusic marked this conversation as resolved.
Show resolved Hide resolved

if (process.env.ENABLE_CLUSTER_MATCHING === 'true') {
runSyncEstimatedClusterMatchingCronjob();
Expand All @@ -376,6 +379,10 @@ export async function bootstrap() {
runCheckPendingUserModelScoreCronjob();
}

if (process.env.SITEMAP_CRON_SECRET !== '') {
runGenerateSitemapOnFrontend();
}
Comment on lines +382 to +384
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();
}


// If we need to deactivate the process use the env var NO MORE
// if (process.env.GIVING_BLOCKS_SERVICE_ACTIVE === 'true') {
// runGivingBlocksProjectSynchronization();
Expand Down
5 changes: 4 additions & 1 deletion src/services/cronJobs/generateSitemapOnFrontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
*/
import { schedule } from 'node-cron';
import axios from 'axios';
import config from '../../config';
import { logger } from '../../utils/logger';

const cronJobTime = '0 0 * * 0'; // Every Sunday at 00:00
// Every Sunday at 00:00
const cronJobTime =
(config.get('GENERATE_SITEMAP_CRONJOB_EXPRESSION') as string) || '0 0 * * 0';

export const runGenerateSitemapOnFrontend = () => {
logger.debug(
Expand Down
Loading