12 The previous filter based on mean_value (recent query rate) is removed as per the new requirement.
12.1 Close Allocations
Finally our list of subgraphs that we want to close allocations for is ready. As a first step, we create a function run_indexer_command()
, which we can use to execute indexer commands through the Indexer CLI:
function(command) {
run_indexer_command = paste0("./shell_python cli '", command, "'")
full_command =tryCatch({
system(full_command, intern = TRUE, ignore.stderr = TRUE)
result =return(paste(result, collapse = "\\n"))
error = function(e) {
}, print(paste("Error executing command:", e$message))
return(NULL)
}) }
Now we can iterate through the current_allocations
data and unallocate from each subgraph. By doing i in 1:nrow(current_allocations)
, the variable i
will increment from 1 through the number of rows contained in current_allocations
. So if there are 20 results in current_allocations
of allocations to be closed, the variable i
will have the values 1 through 20, incrementing by 1 on each iteration through the for
loop.
To avoid issues, we will go one subgraph at a time, doing: 1. queue the unallocation with: graph indexer actions queue unallocate
2. approve the action to unallocate from the one subgraph with: graph indexer actions approve
3. execute the unallocation with: graph indexer actions execute approved
# for (i in 1:nrow(current_allocations)){
# # print update
# print(paste('Unallocating from:', current_allocations[i,]$deployment))
# # queue unallocation
# unallocate_output = run_indexer_command(paste0("graph indexer actions queue unallocate ",current_allocations[i,]$deployment," ", current_allocations[i,]$id, " --network arbitrum-one"))
# # Replace the escaped newlines with actual newlines
# unallocate_output = gsub("\\\\n", "\n", unallocate_output)
# # show outputs
# print(unallocate_output)
# # Extract the action_id using a regular expression
# action_id = as.numeric(str_extract(unallocate_output, "(?<=\n│ )[0-9]+(?= │ arbitrum-one)"))
# # now can execute the unallocation using the extracted action_id
# run_indexer_command(paste0("graph indexer actions approve ", action_id))
# # execute unallocation
# unallocate_output = run_indexer_command("graph indexer actions execute approved")
# # show outputs
# print(unallocate_output)
# }
Nice! Next we will begin the process to decide new allocations, by viewing the list of subgraphs we currently have synced. Next section
save.image('/root/github/indexer_analytics_tutorial/data/chapters_snapshots/04-close_allocations.RData')