-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bde4f6
commit 0fb0b97
Showing
6 changed files
with
70 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 38 additions & 30 deletions
68
indexer/services/roundtable/src/tasks/refresh-vault-pnl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,53 @@ | ||
import { logger, stats } from '@dydxprotocol-indexer/base'; | ||
import { | ||
VaultPnlTicksView | ||
VaultPnlTicksView, | ||
} from '@dydxprotocol-indexer/postgres'; | ||
import { DateTime } from 'luxon'; | ||
|
||
import config from '../config'; | ||
|
||
/** | ||
* Update the affiliate info for all affiliate addresses. | ||
* Refresh the vault pnl ticks views. | ||
*/ | ||
export default async function runTask(): Promise<void> { | ||
const taskStart: number = Date.now(); | ||
|
||
const currentTime: DateTime = DateTime.utc(); | ||
if (currentTime.diff( | ||
currentTime.startOf('hour') | ||
).toMillis() < config.TIME_WINDOW_FOR_REFRESH_MS) { | ||
logger.info({ | ||
at: 'refresh-vault-pnl#runTask', | ||
message: 'Refreshing vault hourly pnl view', | ||
currentTime, | ||
}); | ||
await VaultPnlTicksView.refreshHourlyView(); | ||
stats.timing( | ||
`${config.SERVICE_NAME}.refresh-vault-pnl.hourly-view.timing`, | ||
Date.now() - taskStart, | ||
) | ||
} | ||
try { | ||
const currentTime: DateTime = DateTime.utc(); | ||
if (currentTime.diff( | ||
currentTime.startOf('hour'), | ||
).toMillis() < config.TIME_WINDOW_FOR_REFRESH_VAULT_PNL_MS) { | ||
logger.info({ | ||
at: 'refresh-vault-pnl#runTask', | ||
message: 'Refreshing vault hourly pnl view', | ||
currentTime, | ||
}); | ||
await VaultPnlTicksView.refreshHourlyView(); | ||
stats.timing( | ||
`${config.SERVICE_NAME}.refresh-vault-pnl.hourly-view.timing`, | ||
Date.now() - taskStart, | ||
); | ||
} | ||
|
||
const refreshDailyStart: number = Date.now(); | ||
if (currentTime.diff( | ||
currentTime.startOf('day') | ||
).toMillis() < config.TIME_WINDOW_FOR_REFRESH_MS) { | ||
logger.info({ | ||
if (currentTime.diff( | ||
currentTime.startOf('day'), | ||
).toMillis() < config.TIME_WINDOW_FOR_REFRESH_VAULT_PNL_MS) { | ||
const refreshDailyStart: number = Date.now(); | ||
logger.info({ | ||
at: 'refresh-vault-pnl#runTask', | ||
message: 'Refreshing vault daily pnl view', | ||
currentTime, | ||
}); | ||
await VaultPnlTicksView.refreshDailyView(); | ||
stats.timing( | ||
`${config.SERVICE_NAME}.refresh-vault-pnl.daily-view.timing`, | ||
Date.now() - refreshDailyStart, | ||
); | ||
} | ||
} catch (error) { | ||
logger.error({ | ||
at: 'refresh-vault-pnl#runTask', | ||
message: 'Refreshing vault daily pnl view', | ||
currentTime, | ||
message: 'Failed to refresh vault pnl views', | ||
error, | ||
}); | ||
await VaultPnlTicksView.refreshDailyView(); | ||
stats.timing( | ||
`${config.SERVICE_NAME}.refresh-vault-pnl.daily-view.timing`, | ||
Date.now() - refreshDailyStart, | ||
); | ||
} | ||
} |