Refactor the LN backend and add more logs

This commit is contained in:
nymkappa
2022-08-08 09:00:11 +02:00
parent c0e6b7af58
commit 47363b477e
9 changed files with 434 additions and 292 deletions

View File

@@ -1,8 +1,8 @@
import DB from '../../database';
import logger from '../../logger';
import lightningApi from '../../api/lightning/lightning-api-factory';
import LightningStatsImporter from './sync-tasks/stats-importer';
import config from '../../config';
import { Common } from '../../api/common';
class LightningStatsUpdater {
public async $startService(): Promise<void> {
@@ -12,29 +12,20 @@ class LightningStatsUpdater {
LightningStatsImporter.$run();
}
private setDateMidnight(date: Date): void {
date.setUTCHours(0);
date.setUTCMinutes(0);
date.setUTCSeconds(0);
date.setUTCMilliseconds(0);
}
private async $runTasks(): Promise<void> {
await this.$logStatsDaily();
setTimeout(() => {
this.$runTasks();
}, 1000 * config.LIGHTNING.NODE_STATS_REFRESH_INTERVAL);
setTimeout(() => { this.$runTasks(); }, 1000 * config.LIGHTNING.STATS_REFRESH_INTERVAL);
}
/**
* Update the latest entry for each node every config.LIGHTNING.NODE_STATS_REFRESH_INTERVAL seconds
* Update the latest entry for each node every config.LIGHTNING.STATS_REFRESH_INTERVAL seconds
*/
private async $logStatsDaily(): Promise<void> {
const date = new Date();
this.setDateMidnight(date);
Common.setDateMidnight(date);
logger.info(`Updating latest networks stats`);
logger.info(`Updating latest network stats`);
const networkGraph = await lightningApi.$getNetworkGraph();
LightningStatsImporter.computeNetworkStats(date.getTime() / 1000, networkGraph);
}