Compare commits
2 commits
85c8e69ee4
...
1c348566f0
Author | SHA1 | Date | |
---|---|---|---|
1c348566f0 | |||
e7c2701d52 |
3 changed files with 28 additions and 0 deletions
26
main.js
26
main.js
|
@ -10,6 +10,9 @@ const config = require('./utils/load_config.js')();
|
||||||
const services = [];
|
const services = [];
|
||||||
const servicesDir = path.join(__dirname, 'services');
|
const servicesDir = path.join(__dirname, 'services');
|
||||||
|
|
||||||
|
let fiatFetched = false;
|
||||||
|
let cryptoFetched = false;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (!config['schedule'])
|
if (!config['schedule'])
|
||||||
throw new Error('The crontab schedule is not set.');
|
throw new Error('The crontab schedule is not set.');
|
||||||
|
@ -34,6 +37,9 @@ async function main() {
|
||||||
schedule.scheduleJob(config['schedule'], async () => {
|
schedule.scheduleJob(config['schedule'], async () => {
|
||||||
console.log('Running scheduled task at:', new Date());
|
console.log('Running scheduled task at:', new Date());
|
||||||
|
|
||||||
|
fiatFetched = false;
|
||||||
|
cryptoFetched = false;
|
||||||
|
|
||||||
for (const srv of services) {
|
for (const srv of services) {
|
||||||
const results = await srv.parseCurrencies();
|
const results = await srv.parseCurrencies();
|
||||||
|
|
||||||
|
@ -42,6 +48,16 @@ async function main() {
|
||||||
|
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
try {
|
try {
|
||||||
|
if (srv.info.type === 'fiat' && fiatFetched) {
|
||||||
|
console.log('Skipping fiat currency collection as data has already been fetched.');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (srv.info.type === 'crypto' && cryptoFetched) {
|
||||||
|
console.log('Skipping crypto currency collection as data has already been fetched.');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const currency = await validateCurrency(result);
|
const currency = await validateCurrency(result);
|
||||||
|
|
||||||
await pool.query(
|
await pool.query(
|
||||||
|
@ -59,6 +75,16 @@ async function main() {
|
||||||
console.error(validationError);
|
console.error(validationError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (srv.info.type === 'crypto') {
|
||||||
|
cryptoFetched = true;
|
||||||
|
console.log('Crypto currency data fetched successfully.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (srv.info.type === 'fiat') {
|
||||||
|
fiatFetched = true;
|
||||||
|
console.log('Fiat currency data fetched successfully.');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("Data not received for writing to the database.");
|
console.error("Data not received for writing to the database.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ const { truncate_number } = require('../utils/truncate_number.js');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
info: {
|
info: {
|
||||||
name: 'CoinMarketCap',
|
name: 'CoinMarketCap',
|
||||||
|
type: 'crypto'
|
||||||
},
|
},
|
||||||
parseCurrencies: async () => {
|
parseCurrencies: async () => {
|
||||||
const promises = config['currency']['crypto'].map(fromCurrency => {
|
const promises = config['currency']['crypto'].map(fromCurrency => {
|
||||||
|
|
|
@ -5,6 +5,7 @@ const { truncate_number } = require('../utils/truncate_number.js');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
info: {
|
info: {
|
||||||
name: 'DuckDuckGo',
|
name: 'DuckDuckGo',
|
||||||
|
type: 'fiat'
|
||||||
},
|
},
|
||||||
parseCurrencies: async () => {
|
parseCurrencies: async () => {
|
||||||
const promises = config['currency']['fiat'].map(fromCurrency => {
|
const promises = config['currency']['fiat'].map(fromCurrency => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue