Skip to content

Commit 08dec1f

Browse files
author
andraz maier
committed
feat: add responsiveness checks for FDC and FTSO providers
1 parent 30f04bf commit 08dec1f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

fdc/management/commands/process_fdc_data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def handle(self, *args, **options):
1616
return
1717

1818
fdc_processor = FdcProcessor(config.fdc)
19+
for client in fdc_processor.providers:
20+
if not client.is_responsive():
21+
logger.error(f"Provider {client} is not responsive.")
22+
1923
processor = DataProcessor(
2024
config.rpc_url, config.syncing_config, config.contracts.relay
2125
)

ftso/management/commands/process_ftso_data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def handle(self, *args, **options):
1616
return
1717

1818
ftso_processor = FtsoProcessor(config.ftso)
19+
for client in ftso_processor.providers:
20+
if not client.is_responsive():
21+
logger.error(f"Provider {client} is not responsive.")
22+
1923
processor = DataProcessor(
2024
config.rpc_url, config.syncing_config, config.contracts.relay
2125
)

processing/client/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ def _validation_status_check(self, response):
3737
return False
3838
return True
3939

40+
def _is_responsive(self, request_url) -> bool:
41+
try:
42+
response = self._get(request_url)
43+
res = response.json()
44+
if res[self.status_keyword] == "NOT_AVAILABLE":
45+
return True
46+
return False
47+
48+
except Exception:
49+
return False
50+
51+
def is_responsive(self) -> bool:
52+
raise NotImplementedError("Subclasses must implement this method")
53+
4054

4155
class FtsoClient(BaseClient):
4256
def get_data(self, voting_round_id: int) -> FtsoDataResponse:
@@ -62,6 +76,9 @@ def get_data(self, voting_round_id: int) -> FtsoDataResponse:
6276
except Exception as e:
6377
raise e
6478

79+
def is_responsive(self) -> bool:
80+
return self._is_responsive("/data/0")
81+
6582

6683
class FdcClient(BaseClient):
6784
status_keyword = "Status"
@@ -80,3 +97,6 @@ def get_data(self, voting_round_id: int) -> FdcDataResponse:
8097
except Exception as e:
8198
logger.error("Error parsing FdcDataResponse")
8299
raise e
100+
101+
def is_responsive(self) -> bool:
102+
return self._is_responsive("/getAttestations/0")

0 commit comments

Comments
 (0)