@@ -34,11 +34,15 @@ export async function up({ context }: Context): Promise<void> {
3434 indexNodes,
3535 } )
3636
37- const targetNode =
37+ const specifiedTargetNode = process . env . INDEXER_PAUSED_TARGET_NODE
38+ const leastDeploymentsNode =
3839 indexNodes . sort ( ( nodeA , nodeB ) => {
3940 return nodeA . deployments . length - nodeB . deployments . length
4041 } ) [ 0 ] ?. id || 'default'
4142
43+ // If the target node is specified, use it. Otherwise, use the node with the least deployments
44+ const targetNode = specifiedTargetNode || leastDeploymentsNode
45+
4246 const pausedDeploymentAssignments =
4347 await graphNode . subgraphDeploymentsAssignments ( SubgraphStatus . PAUSED )
4448
@@ -49,7 +53,7 @@ export async function up({ context }: Context): Promise<void> {
4953 )
5054
5155 logger . info (
52- 'Reassigning paused subgraphs to valid node_id (targetNode), then pausing ' ,
56+ 'Pausing subgraphs, then reassigning them to valid node_id (targetNode)' ,
5357 {
5458 pausedSubgraphs : virtuallyPausedDeploymentAssignments . map (
5559 details => details . id ,
@@ -59,9 +63,10 @@ export async function up({ context }: Context): Promise<void> {
5963 )
6064
6165 for ( const deploymentAssignment of virtuallyPausedDeploymentAssignments ) {
62- await graphNode . reassign ( deploymentAssignment . id , targetNode )
66+ // Here we first pause the subgraph to ensure it does not start indexing
6367 await graphNode . pause ( deploymentAssignment . id )
64- logger . debug ( 'Successfully reassigned and paused deployment' , {
68+ await graphNode . reassign ( deploymentAssignment . id , targetNode )
69+ logger . debug ( 'Successfully paused and reassigned deployment' , {
6570 deployment : deploymentAssignment . id . ipfsHash ,
6671 } )
6772 }
0 commit comments