-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1900 from Giveth/feat/sitemap_cron_job
Feat/Cron job for sitemap generating on FE
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`, | ||
}, | ||
}, | ||
); | ||
logger.info('runGenerateSitemapOnFrontend() response:', response.data); | ||
} catch (error) { | ||
logger.error('runGenerateSitemapOnFrontend() error:', error.message); | ||
} | ||
logger.debug('runGenerateSitemapOnFrontend() job has finished'); | ||
}); | ||
}; |