@@ -37,6 +37,7 @@ import {
37
37
networkIsL1 ,
38
38
DeploymentManagementMode ,
39
39
SubgraphStatus ,
40
+ sequentialTimerMap ,
40
41
} from '@graphprotocol/indexer-common'
41
42
42
43
import PQueue from 'p-queue'
@@ -253,40 +254,41 @@ export class Agent {
253
254
const requestIntervalSmall = this . pollingInterval
254
255
const requestIntervalLarge = this . pollingInterval * 5
255
256
const logger = this . logger . child ( { component : 'ReconciliationLoop' } )
256
- const currentEpochNumber : Eventual < NetworkMapped < number > > = timer (
257
- requestIntervalLarge ,
258
- ) . tryMap (
259
- async ( ) =>
260
- await this . multiNetworks . map ( ( { network } ) => {
261
- logger . trace ( 'Fetching current epoch number' , {
262
- protocolNetwork : network . specification . networkIdentifier ,
263
- } )
264
- return network . networkMonitor . currentEpochNumber ( )
265
- } ) ,
266
- {
267
- onError : error =>
268
- logger . warn ( `Failed to fetch current epoch` , { error } ) ,
269
- } ,
270
- )
257
+ const currentEpochNumber : Eventual < NetworkMapped < number > > =
258
+ sequentialTimerMap (
259
+ { logger , milliseconds : requestIntervalLarge } ,
260
+ async ( ) =>
261
+ await this . multiNetworks . map ( ( { network } ) => {
262
+ logger . trace ( 'Fetching current epoch number' , {
263
+ protocolNetwork : network . specification . networkIdentifier ,
264
+ } )
265
+ return network . networkMonitor . currentEpochNumber ( )
266
+ } ) ,
267
+ {
268
+ onError : error =>
269
+ logger . warn ( `Failed to fetch current epoch` , { error } ) ,
270
+ } ,
271
+ )
271
272
272
- const maxAllocationEpochs : Eventual < NetworkMapped < number > > = timer (
273
- requestIntervalLarge ,
274
- ) . tryMap (
275
- ( ) =>
276
- this . multiNetworks . map ( ( { network } ) => {
277
- logger . trace ( 'Fetching max allocation epochs' , {
278
- protocolNetwork : network . specification . networkIdentifier ,
279
- } )
280
- return network . contracts . staking . maxAllocationEpochs ( )
281
- } ) ,
282
- {
283
- onError : error =>
284
- logger . warn ( `Failed to fetch max allocation epochs` , { error } ) ,
285
- } ,
286
- )
273
+ const maxAllocationEpochs : Eventual < NetworkMapped < number > > =
274
+ sequentialTimerMap (
275
+ { logger , milliseconds : requestIntervalLarge } ,
276
+ ( ) =>
277
+ this . multiNetworks . map ( ( { network } ) => {
278
+ logger . trace ( 'Fetching max allocation epochs' , {
279
+ protocolNetwork : network . specification . networkIdentifier ,
280
+ } )
281
+ return network . contracts . staking . maxAllocationEpochs ( )
282
+ } ) ,
283
+ {
284
+ onError : error =>
285
+ logger . warn ( `Failed to fetch max allocation epochs` , { error } ) ,
286
+ } ,
287
+ )
287
288
288
289
const indexingRules : Eventual < NetworkMapped < IndexingRuleAttributes [ ] > > =
289
- timer ( requestIntervalSmall ) . tryMap (
290
+ sequentialTimerMap (
291
+ { logger, milliseconds : requestIntervalSmall } ,
290
292
async ( ) => {
291
293
return this . multiNetworks . map ( async ( { network, operator } ) => {
292
294
logger . trace ( 'Fetching indexing rules' , {
@@ -322,24 +324,25 @@ export class Agent {
322
324
} ,
323
325
)
324
326
325
- const activeDeployments : Eventual < SubgraphDeploymentID [ ] > = timer (
326
- requestIntervalSmall ,
327
- ) . tryMap (
328
- ( ) => {
329
- logger . trace ( 'Fetching active deployments' )
330
- return this . graphNode . subgraphDeployments ( )
331
- } ,
332
- {
333
- onError : error =>
334
- logger . warn (
335
- `Failed to obtain active deployments, trying again later` ,
336
- { error } ,
337
- ) ,
338
- } ,
339
- )
327
+ const activeDeployments : Eventual < SubgraphDeploymentID [ ] > =
328
+ sequentialTimerMap (
329
+ { logger , milliseconds : requestIntervalSmall } ,
330
+ ( ) => {
331
+ logger . trace ( 'Fetching active deployments' )
332
+ return this . graphNode . subgraphDeployments ( )
333
+ } ,
334
+ {
335
+ onError : error =>
336
+ logger . warn (
337
+ `Failed to obtain active deployments, trying again later` ,
338
+ { error } ,
339
+ ) ,
340
+ } ,
341
+ )
340
342
341
343
const networkDeployments : Eventual < NetworkMapped < SubgraphDeployment [ ] > > =
342
- timer ( requestIntervalSmall ) . tryMap (
344
+ sequentialTimerMap (
345
+ { logger, milliseconds : requestIntervalSmall } ,
343
346
async ( ) =>
344
347
await this . multiNetworks . map ( ( { network } ) => {
345
348
logger . trace ( 'Fetching network deployments' , {
@@ -358,7 +361,8 @@ export class Agent {
358
361
359
362
const eligibleTransferDeployments : Eventual <
360
363
NetworkMapped < TransferredSubgraphDeployment [ ] >
361
- > = timer ( requestIntervalLarge ) . tryMap (
364
+ > = sequentialTimerMap (
365
+ { logger, milliseconds : requestIntervalLarge } ,
362
366
async ( ) => {
363
367
// Return early if the auto migration feature is disabled.
364
368
if ( ! this . autoMigrationSupport ) {
@@ -558,23 +562,23 @@ export class Agent {
558
562
} ,
559
563
)
560
564
561
- const activeAllocations : Eventual < NetworkMapped < Allocation [ ] > > = timer (
562
- requestIntervalSmall ,
563
- ) . tryMap (
564
- ( ) =>
565
- this . multiNetworks . map ( ( { network } ) => {
566
- logger . trace ( 'Fetching active allocations' , {
567
- protocolNetwork : network . specification . networkIdentifier ,
568
- } )
569
- return network . networkMonitor . allocations ( AllocationStatus . ACTIVE )
570
- } ) ,
571
- {
572
- onError : ( ) =>
573
- logger . warn (
574
- `Failed to obtain active allocations, trying again later` ,
575
- ) ,
576
- } ,
577
- )
565
+ const activeAllocations : Eventual < NetworkMapped < Allocation [ ] > > =
566
+ sequentialTimerMap (
567
+ { logger , milliseconds : requestIntervalSmall } ,
568
+ ( ) =>
569
+ this . multiNetworks . map ( ( { network } ) => {
570
+ logger . trace ( 'Fetching active allocations' , {
571
+ protocolNetwork : network . specification . networkIdentifier ,
572
+ } )
573
+ return network . networkMonitor . allocations ( AllocationStatus . ACTIVE )
574
+ } ) ,
575
+ {
576
+ onError : ( ) =>
577
+ logger . warn (
578
+ `Failed to obtain active allocations, trying again later` ,
579
+ ) ,
580
+ } ,
581
+ )
578
582
579
583
// `activeAllocations` is used to trigger this Eventual, but not really needed
580
584
// inside.
0 commit comments