Skip to content

Commit e0550b8

Browse files
committed
Move last_health_check_ts as a property of node.
1 parent 22692f1 commit e0550b8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

typesense/api_call.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import json
23
import time
34

@@ -14,15 +15,17 @@ class ApiCall(object):
1415

1516
def __init__(self, config):
1617
self.config = config
17-
self.nodes = self.config.nodes
18+
self.nodes = copy.deepcopy(self.config.nodes)
1819
self.node_index = 0
19-
self.last_health_check_ts = int(time.time())
2020

21-
def _check_failed_node(self):
21+
for node in self.nodes:
22+
node.last_health_check_ts = int(time.time())
23+
24+
def _check_failed_node(self, node):
2225
current_epoch_ts = int(time.time())
23-
check_node = ((current_epoch_ts - self.last_health_check_ts) > ApiCall.CHECK_FAILED_NODE_INTERVAL_S)
26+
check_node = ((current_epoch_ts - node.last_health_check_ts) > ApiCall.CHECK_FAILED_NODE_INTERVAL_S)
2427
if check_node:
25-
self.last_health_check_ts = current_epoch_ts
28+
node.last_health_check_ts = current_epoch_ts
2629

2730
return check_node
2831

@@ -33,8 +36,9 @@ def get_node(self):
3336
while i < len(self.nodes):
3437
i += 1
3538
self.node_index = (self.node_index + 1) % len(self.nodes)
36-
if self.nodes[self.node_index].healthy or self._check_failed_node():
37-
return self.nodes[self.node_index]
39+
node = self.nodes[self.node_index]
40+
if node.healthy or self._check_failed_node(node):
41+
return node
3842

3943
# None of the nodes are marked healthy, but some of them could have become healthy since last health check.
4044
# So we will just return the next node.

0 commit comments

Comments
 (0)