From 8d7e5e9abc56b1c56d9a26e32c6fb4efac100d1a Mon Sep 17 00:00:00 2001 From: ignatkhar Date: Mon, 14 Oct 2024 13:42:00 +0200 Subject: [PATCH] Update README.md. Add cron documentation --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index f165c2e..05c07c3 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,62 @@ The `pages/api` directory is mapped to `/api/*`. Files in this directory are tre This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. +## Cron Job for API Call in Docker Container +### Overview + +This project contains a cron job that periodically calls an API to update validator details. The cron job is implemented in a Docker container and is scheduled to run every 5 minutes. Below is a detailed explanation of the setup. +### Cron Job Setup + +The cron job is defined in the crontab file and is scheduled to run every 5 minutes: + +```bash +*/5 * * * * /validator_dapp/callApi.sh 2>> /validator_dapp/logg.log +``` + +This command executes the callApi.sh script, which triggers a Node.js script that sends a POST request to the validator update API. Any errors encountered during execution are logged into logg.log. +### Dockerfile Setup + +The cron job is copied into the Docker container using the following command in the Dockerfile. + +```bash +COPY crontab /etc/crontabs/root +``` + +This ensures that the cron job is configured when the Docker container is built. +### API Call Script + +The cron job executes a shell script (callApi.sh) which triggers the following Node.js code to make a POST request to the specified API endpoint. + +```javascript +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; + +const axios = require('axios'); + + +const callApi = async () => { + + try { + + const response = await axios.post('https://bloxberg-qa-traefik.mpdl.mpg.de/api/update-validators-details'); + + console.log('API called successfully:', response.data); + + } catch (error) { + + console.log('Error calling API:', error); + + } + +}; + + +callApi(); +``` + +### Note: SSL certificate verification is disabled for testing purposes by setting process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'. This should be removed in production. + + + ## Learn More To learn more about Next.js, take a look at the following resources: