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

Feat/Cron job for sitemap generating on FE #1900

Merged
merged 1 commit into from
Jan 3, 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
4 changes: 4 additions & 0 deletions src/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { runCheckPendingRecurringDonationsCronJob } from '../services/cronJobs/s
import { runCheckQRTransactionJob } from '../services/cronJobs/checkQRTransactionJob';
import { addClient } from '../services/sse/sse';
import { runCheckPendingUserModelScoreCronjob } from '../services/cronJobs/syncUsersModelScore';
import { runGenerateSitemapOnFrontend } from '../services/cronJobs/generateSitemapOnFrontend';

Resource.validate = validate;

Expand Down Expand Up @@ -421,6 +422,9 @@ export async function bootstrap() {
runUpdateRecurringDonationStream();
runCheckUserSuperTokenBalancesJob();
}
if (process.env.SITEMAP_CRON_SECRET !== '') {
runGenerateSitemapOnFrontend();
}
logger.debug(
'initializeCronJobs() before runCheckActiveStatusOfQfRounds() ',
new Date(),
Expand Down
39 changes: 39 additions & 0 deletions src/services/cronJobs/generateSitemapOnFrontend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* This cron job is responsible for generating sitemap on frontend.
*
* It sends a request to frontend to generate sitemap.
*
* It is scheduled to run every Sunday at 00:00.
*
* It use SITEMAP_CRON_SECRET that is set in .env file and MUST be the same on frontend!
*/
import { schedule } from 'node-cron';
import axios from 'axios';
import { logger } from '../../utils/logger';

const cronJobTime = '0 0 * * 0'; // Every Sunday at 00:00

export const runGenerateSitemapOnFrontend = () => {
logger.debug(
'runGenerateSitemapOnFrontend() has been called, cronJobTime:',
cronJobTime,
);

schedule(cronJobTime, async () => {
logger.debug('runGenerateSitemapOnFrontend() job has started');
try {
const response = await axios.get(
`{process.env.FRONTEND_URL}/api/generate-sitemap`,
{
headers: {
Authorization: `Bearer {process.env.SITEMAP_CRON_SECRET}`,
kkatusic marked this conversation as resolved.
Show resolved Hide resolved
},
},
);
logger.info('runGenerateSitemapOnFrontend() response:', response.data);
} catch (error) {
logger.error('runGenerateSitemapOnFrontend() error:', error.message);
}
logger.debug('runGenerateSitemapOnFrontend() job has finished');
});
};
Loading