Skip to content

Commit

Permalink
Update node status
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Oct 2, 2024
1 parent 8769353 commit d719f01
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stats-backend/api2/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ def extract_wallets_and_ids():
def bulk_update_node_statuses(nodes_data):
status_history_to_create = []
redis_updates = {}
nodes_to_update = []

for node_id, is_online in nodes_data:
latest_status = r.get(f"provider:{node_id}:status")
Expand All @@ -1840,10 +1841,15 @@ def bulk_update_node_statuses(nodes_data):
)
redis_updates[f"provider:{node_id}:status"] = str(is_online)

if not is_online:
nodes_to_update.append(node_id)

if status_history_to_create:
with transaction.atomic():
NodeStatusHistory.objects.bulk_create(status_history_to_create)

# Efficiently update Node objects for offline nodes
Node.objects.filter(node_id__in=nodes_to_update).update(online=False)

if redis_updates:
r.mset(redis_updates)
Expand Down

0 comments on commit d719f01

Please sign in to comment.