Skip to content

Commit

Permalink
run wallet scanner once a day
Browse files Browse the repository at this point in the history
  • Loading branch information
DZariusz committed Mar 7, 2024
1 parent 4a22d12 commit a54e5f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

## [5.10.3] - 2024-03-07
### Fixed
- run wallet scanner once a day

## [5.10.2] - 2024-02-15
### Fixed
- add missing wallet in report
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sanctuary",
"version": "5.10.2",
"version": "5.10.3",
"repository": {
"type": "git",
"url": "git+https://github.com/umbrella-network/sanctuary.git"
Expand Down
18 changes: 14 additions & 4 deletions src/workers/MetricsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class MetricsWorker extends BasicWorker {
@inject(KeysUpdateService) private keysUpdateService!: KeysUpdateService;
@inject(ValidatorsWalletsScanner) private validatorsWalletsScanner: ValidatorsWalletsScanner;

private lastWalletRun = 0;

apply = async (job: Bull.Job): Promise<void> => {
this.logger.debug(`[MetricsWorker] apply for ${job.id}`);
const chains = Object.keys(this.settings.blockchain.blockchainScanner) as ChainsIds[];
Expand All @@ -42,14 +44,22 @@ class MetricsWorker extends BasicWorker {

if (lastSyncedBlock <= 0) return;

const now = new Date();
const allowExecution = now.getHours() == 0 && now.getMinutes() < 5;

await Promise.all([
this.onChainTxFetcher.call(chainId, lastSyncedBlock),
allowExecution ? this.validatorsWalletsScanner.call(chainId) : undefined,
this.allowWalletScanner() ? this.validatorsWalletsScanner.call(chainId) : undefined,
]);
};

private allowWalletScanner(): boolean {
const now = Date.now();

if (now - this.lastWalletRun > 60 * 60 * 24) {
this.lastWalletRun = now;
return true;
}

return false;
}
}

export default MetricsWorker;

0 comments on commit a54e5f2

Please sign in to comment.