-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr1.js
More file actions
34 lines (29 loc) · 758 Bytes
/
pr1.js
File metadata and controls
34 lines (29 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const axios = require("axios");
const { producer } = require("./kafka");
(async () => {
try {
await getApiData();
setInterval(getApiData, 30*60*3600);
} catch (err) {
console.error(err);
}
})();
/**
* Recover API data every 30 minutes and store them
*/
async function getApiData() {
try {
const { data } = await axios.get("https://api.covid19api.com/summary");
await producer.connect();
await producer.send({
topic: "topic1",
messages: [
{ value: JSON.stringify(data) },
],
});
await producer.disconnect();
console.info("Data recovered from API");
} catch (err) {
console.error(err);
}
}