Skip to content

Commit

Permalink
Update README.md. Add cron documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatkhar authored Oct 14, 2024
1 parent 48c54e7 commit 8d7e5e9
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8d7e5e9

Please sign in to comment.