|
1 | 1 | import moment from "moment"; |
2 | 2 | import type { Address } from "viem"; |
3 | | - |
4 | 3 | import type { PoolExternalAPYResult, PoolPointsResult } from "../../pools"; |
5 | 4 | import { getPoolExternalAPY, getPoolPoints } from "../../pools"; |
6 | 5 | import { getPoolExtraAPY } from "../../pools/extraAPY/apy"; |
@@ -52,8 +51,10 @@ import type { TokenExtraRewardsResult } from "../../tokens/tokenExtraRewards"; |
52 | 51 | import { getTokenExtraRewards } from "../../tokens/tokenExtraRewards"; |
53 | 52 | import type { NetworkType } from "../chains"; |
54 | 53 | import { getChainId, getNetworkType, supportedChains } from "../chains"; |
| 54 | +import { ONE_SHOT_TIMEOUT } from "../config"; |
55 | 55 | import type { IOutputWriter, OneShotOutput } from "../output"; |
56 | 56 | import { captureException } from "../sentry"; |
| 57 | +import { withTimeout } from "../utils"; |
57 | 58 | import { POOL_APY_TASK_INTERVAL, TOKEN_APY_TASK_INTERVAL } from "./constants"; |
58 | 59 |
|
59 | 60 | export type ApyDetails = Apy & { lastUpdated: string }; |
@@ -319,7 +320,7 @@ export class Fetcher { |
319 | 320 | setInterval(quarterTask, POOL_APY_TASK_INTERVAL); |
320 | 321 | } |
321 | 322 |
|
322 | | - public async oneShot(outputWriter: IOutputWriter): Promise<void> { |
| 323 | + async #oneShot(outputWriter: IOutputWriter): Promise<void> { |
323 | 324 | console.log("[SYSTEM]: Starting one-shot mode"); |
324 | 325 |
|
325 | 326 | await this.runNetworkRewards(); |
@@ -384,6 +385,17 @@ export class Fetcher { |
384 | 385 | `[SYSTEM]: One-shot mode completed. Chains: ${output.metadata.totalChains}, Successful: ${output.metadata.successfulChains}, Failed: ${output.metadata.failedChains}`, |
385 | 386 | ); |
386 | 387 | } |
| 388 | + |
| 389 | + public async oneShot(outputWriter: IOutputWriter): Promise<void> { |
| 390 | + if (ONE_SHOT_TIMEOUT) { |
| 391 | + await withTimeout( |
| 392 | + () => this.#oneShot(outputWriter), |
| 393 | + ONE_SHOT_TIMEOUT * 1000, |
| 394 | + ); |
| 395 | + } else { |
| 396 | + await this.#oneShot(outputWriter); |
| 397 | + } |
| 398 | + } |
387 | 399 | } |
388 | 400 |
|
389 | 401 | interface LogRewardsProps { |
|
0 commit comments