floriday/index.js

31 lines
918 B
JavaScript

import moment from 'moment';
import { getClientToken } from './utils.js';
import dotenv from 'dotenv';
dotenv.config();
import models from './models/index.js';
let tokenExpirationDate = await getClientToken(models);
try {
setInterval(async () => {
console.log('Querying the API to check for new data...');
console.log('Current token expiration date: ', tokenExpirationDate);
if (moment().isAfter(tokenExpirationDate)) {
console.log('Token expired, getting a new one...');
tokenExpirationDate = await getClientToken(models);
}
}, process.env.STATUS == 'development' ? 2500 : 5000);
} catch (error) {
console.error('Unable to connect to the database:', error);
}
console.log = function () {
let args = Array.prototype.slice.call(arguments);
args.unshift(new moment().format('HH:mm:ss') + ' -');
console.info.apply(console, args);
};