2022-07-06 13:20:37 +02:00
|
|
|
import logger from '../../logger';
|
|
|
|
import lightningApi from '../../api/lightning/lightning-api-factory';
|
2022-08-01 17:48:04 +02:00
|
|
|
import LightningStatsImporter from './sync-tasks/stats-importer';
|
2022-08-04 18:27:36 +02:00
|
|
|
import config from '../../config';
|
2022-08-08 09:00:11 +02:00
|
|
|
import { Common } from '../../api/common';
|
2022-04-19 17:37:06 +04:00
|
|
|
|
|
|
|
class LightningStatsUpdater {
|
2022-08-01 17:48:04 +02:00
|
|
|
public async $startService(): Promise<void> {
|
2022-07-06 21:43:47 +02:00
|
|
|
logger.info('Starting Lightning Stats service');
|
2022-04-19 17:37:06 +04:00
|
|
|
|
2022-08-05 12:32:20 +02:00
|
|
|
await this.$runTasks();
|
|
|
|
LightningStatsImporter.$run();
|
2022-07-10 20:01:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private async $runTasks(): Promise<void> {
|
2022-08-01 18:21:45 +02:00
|
|
|
await this.$logStatsDaily();
|
2022-07-10 20:01:15 +02:00
|
|
|
|
2022-08-08 09:00:11 +02:00
|
|
|
setTimeout(() => { this.$runTasks(); }, 1000 * config.LIGHTNING.STATS_REFRESH_INTERVAL);
|
2022-04-19 17:37:06 +04:00
|
|
|
}
|
|
|
|
|
2022-08-04 18:27:36 +02:00
|
|
|
/**
|
2022-08-08 09:00:11 +02:00
|
|
|
* Update the latest entry for each node every config.LIGHTNING.STATS_REFRESH_INTERVAL seconds
|
2022-08-04 18:27:36 +02:00
|
|
|
*/
|
2022-08-01 18:21:45 +02:00
|
|
|
private async $logStatsDaily(): Promise<void> {
|
|
|
|
const date = new Date();
|
2022-08-08 09:00:11 +02:00
|
|
|
Common.setDateMidnight(date);
|
2022-08-01 18:21:45 +02:00
|
|
|
const networkGraph = await lightningApi.$getNetworkGraph();
|
2022-08-11 16:51:09 +02:00
|
|
|
await LightningStatsImporter.computeNetworkStats(date.getTime() / 1000, networkGraph);
|
2022-08-09 10:28:40 +02:00
|
|
|
|
|
|
|
logger.info(`Updated latest network stats`);
|
2022-04-27 02:52:23 +04:00
|
|
|
}
|
2022-04-19 17:37:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new LightningStatsUpdater();
|