|
6 | 6 |
|
7 | 7 | import backoff |
8 | 8 | from gql import Client, gql |
| 9 | +from gql.transport.exceptions import TransportQueryError |
9 | 10 | from gql.transport.requests import RequestsHTTPTransport |
10 | 11 | from requests import RequestException |
11 | 12 |
|
@@ -42,9 +43,32 @@ def get_network_allocated_subgraphs(network: str) -> Set[str]: |
42 | 43 |
|
43 | 44 |
|
44 | 45 | def get_allocated_subgraphs() -> Set[str]: |
45 | | - """Get the indexer's subgraph allocations for all Graph networks.""" |
| 46 | + """ |
| 47 | + Get the indexer's subgraph allocations for all Graph networks. |
| 48 | +
|
| 49 | + Will try for both mainnet and arbitrum-one networks. If one of them fails, it |
| 50 | + will ignore it (happens if the indexer-agent is in single network mode). |
| 51 | + If both fail, it will raise the exception. |
| 52 | + """ |
46 | 53 |
|
47 | 54 | networks = ("mainnet", "arbitrum-one") |
48 | | - results = map(get_network_allocated_subgraphs, networks) |
| 55 | + results = [] |
| 56 | + |
| 57 | + for network in networks: |
| 58 | + try: |
| 59 | + results += [get_network_allocated_subgraphs(network)] |
| 60 | + except TransportQueryError: |
| 61 | + logging.info( |
| 62 | + f"Failed to get indexer allocations for network '{network}'. Ignoring." |
| 63 | + ) |
| 64 | + results += [None] |
| 65 | + |
| 66 | + if all(r is None for r in results): |
| 67 | + raise RuntimeError( |
| 68 | + f"Failed to query indexer allocations for all Graph networks: {networks}." |
| 69 | + ) |
| 70 | + |
| 71 | + # Replace None's with empty set |
| 72 | + results = [r if r is not None else set() for r in results] |
49 | 73 |
|
50 | 74 | return set.union(*results) |
0 commit comments