mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 12:43:12 +03:00
Рефакторинг кода
This commit is contained in:
parent
490422504e
commit
75a97ff2ca
1 changed files with 26 additions and 15 deletions
|
@ -5,23 +5,34 @@ const cron = require('cron-validator');
|
||||||
const save_fiat = require('./save_fiat');
|
const save_fiat = require('./save_fiat');
|
||||||
const save_crypto = require('./save_crypto');
|
const save_crypto = require('./save_crypto');
|
||||||
|
|
||||||
async function main() {
|
async function validateSchedule(schedule) {
|
||||||
await require('../shared/database/src/create_table')();
|
if (!schedule) throw new Error('The crontab schedule is not set');
|
||||||
|
if (!cron.isValidCron(schedule, { alias: true }))
|
||||||
const config_schedule = config['currency']['collecting']['schedule'];
|
|
||||||
if (!config_schedule) throw new Error('The crontab schedule is not set');
|
|
||||||
if (!cron.isValidCron(config_schedule, { alias: true }))
|
|
||||||
throw new Error('The crontab is invalid');
|
throw new Error('The crontab is invalid');
|
||||||
|
|
||||||
await save_fiat();
|
|
||||||
await save_crypto();
|
|
||||||
|
|
||||||
schedule.scheduleJob(config_schedule, async function () {
|
|
||||||
await save_fiat();
|
|
||||||
await save_crypto();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
async function initialize() {
|
||||||
|
await require('../shared/database/src/create_table')();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runTasks() {
|
||||||
|
await Promise.all([save_fiat(), save_crypto()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await initialize();
|
||||||
|
await validateSchedule(config['currency']['collecting']['schedule']);
|
||||||
|
|
||||||
|
await runTasks();
|
||||||
|
|
||||||
|
schedule.scheduleJob(
|
||||||
|
config['currency']['collecting']['schedule'],
|
||||||
|
runTasks,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((err) => {
|
||||||
|
logger.error('Error in main execution:', err);
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = { main };
|
module.exports = { main };
|
||||||
|
|
Loading…
Add table
Reference in a new issue