Adding multiple fs.watch-ers to handle Bisq restarts.
This commit is contained in:
parent
3df36cd3b8
commit
66c565a3d7
@ -20,25 +20,16 @@ class Bisq {
|
|||||||
};
|
};
|
||||||
private price: number = 0;
|
private price: number = 0;
|
||||||
private priceUpdateCallbackFunction: ((price: number) => void) | undefined;
|
private priceUpdateCallbackFunction: ((price: number) => void) | undefined;
|
||||||
|
private subdirectoryWatcher: fs.FSWatcher | undefined;
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
startBisqService(): void {
|
startBisqService(): void {
|
||||||
this.loadBisqDumpFile();
|
this.loadBisqDumpFile();
|
||||||
|
|
||||||
let fsWait: NodeJS.Timeout | null = null;
|
|
||||||
fs.watch(config.BSQ_BLOCKS_DATA_PATH, { recursive: true }, () => {
|
|
||||||
if (fsWait) {
|
|
||||||
clearTimeout(fsWait);
|
|
||||||
}
|
|
||||||
fsWait = setTimeout(() => {
|
|
||||||
console.log(`Change detected in the Bisq data folder.`);
|
|
||||||
this.loadBisqDumpFile();
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
setInterval(this.updatePrice.bind(this), 1000 * 60 * 60);
|
setInterval(this.updatePrice.bind(this), 1000 * 60 * 60);
|
||||||
this.updatePrice();
|
this.updatePrice();
|
||||||
|
this.startTopLevelDirectoryWatcher();
|
||||||
|
this.restartSubDirectoryWatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransaction(txId: string): BisqTransaction | undefined {
|
getTransaction(txId: string): BisqTransaction | undefined {
|
||||||
@ -73,6 +64,36 @@ class Bisq {
|
|||||||
return this.latestBlockHeight;
|
return this.latestBlockHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private startTopLevelDirectoryWatcher() {
|
||||||
|
let fsWait: NodeJS.Timeout | null = null;
|
||||||
|
fs.watch(config.BSQ_BLOCKS_DATA_PATH, () => {
|
||||||
|
if (fsWait) {
|
||||||
|
clearTimeout(fsWait);
|
||||||
|
}
|
||||||
|
fsWait = setTimeout(() => {
|
||||||
|
console.log(`Change detected in the top level Bisq data folder. Resetting inner watcher.`);
|
||||||
|
this.restartSubDirectoryWatcher();
|
||||||
|
}, 15000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private restartSubDirectoryWatcher() {
|
||||||
|
if (this.subdirectoryWatcher) {
|
||||||
|
this.subdirectoryWatcher.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
let fsWait: NodeJS.Timeout | null = null;
|
||||||
|
this.subdirectoryWatcher = fs.watch(config.BSQ_BLOCKS_DATA_PATH + '/all', () => {
|
||||||
|
if (fsWait) {
|
||||||
|
clearTimeout(fsWait);
|
||||||
|
}
|
||||||
|
fsWait = setTimeout(() => {
|
||||||
|
console.log(`Change detected in the Bisq data folder.`);
|
||||||
|
this.loadBisqDumpFile();
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private updatePrice() {
|
private updatePrice() {
|
||||||
request('https://markets.bisq.network/api/trades/?market=bsq_btc', { json: true }, (err, res, trades: BisqTrade[]) => {
|
request('https://markets.bisq.network/api/trades/?market=bsq_btc', { json: true }, (err, res, trades: BisqTrade[]) => {
|
||||||
if (err) { return console.log(err); }
|
if (err) { return console.log(err); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user