Skip to content

Commit

Permalink
refactor: extract logic for checking new node providers to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
louisevelayo committed Nov 10, 2023
1 parent 9066663 commit 23d21fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion node_monitor/ic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Nodes(BaseModel):
nodes: List[Node]

class NodeProvider(BaseModel):
principal_id: Principal
display_name: str
principal_id: str

class NodeProviders(BaseModel):
node_providers: List[NodeProvider]
Expand Down
14 changes: 4 additions & 10 deletions node_monitor/node_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from node_monitor.node_provider_db import NodeProviderDB
from node_monitor.node_monitor_helpers.get_compromised_nodes import \
get_compromised_nodes
from node_monitor.node_monitor_helpers.get_new_node_providers import \
get_new_node_providers
import node_monitor.node_monitor_helpers.messages as messages

Seconds = int
Expand Down Expand Up @@ -198,16 +200,8 @@ def update_node_provider_lookup_if_new(
for node_provider in node_providers_api.node_providers
}
node_providers_db = self.node_provider_db.get_subscribers_as_dict()

principals_api = set(node_providers_api_dict.keys())
principals_db = set(node_providers_db.keys())

principals_new = principals_api - principals_db
node_providers_new = [
NodeProvider(
display_name=node_providers_api_dict[principal_id],
principal_id=principal_id
) for principal_id in principals_new]
node_providers_new = get_new_node_providers(
node_providers_api_dict, node_providers_db)

query = """
INSERT INTO subscribers (
Expand Down
21 changes: 21 additions & 0 deletions node_monitor/node_monitor_helpers/get_new_node_providers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Dict, List, Any
from node_monitor.ic_api import NodeProvider

Principal = str

def get_new_node_providers(
node_providers_api_dict: Dict[Principal, str],
node_providers_db: Dict[Principal, Dict[str, Any]],
) -> List[NodeProvider]:
principals_api = set(node_providers_api_dict.keys())
principals_db = set(node_providers_db.keys())
principals_new = principals_api - principals_db

node_providers_new = [
NodeProvider(
display_name=node_providers_api_dict[principal_id],
principal_id=principal_id
) for principal_id in principals_new
]

return node_providers_new

0 comments on commit 23d21fb

Please sign in to comment.