Skip to content

Commit fe5e952

Browse files
committed
INDY-2215: add update_interval() to RepeatingTimer
Signed-off-by: toktar <[email protected]>
1 parent 349da58 commit fe5e952

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

plenum/common/timer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ def stop(self):
8181
return
8282
self._active = False
8383
self._timer.cancel(self._callback)
84+
85+
def update_interval(self, interval):
86+
self._interval = interval

plenum/server/catchup/cons_proof_service.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@ def __init__(self,
4848
self._cons_proofs = {}
4949
self._already_asked_for_cons_proofs_without_timeout = False
5050
self._last_txn_3PC_key = {}
51-
self._ledger_status_timer = None
52-
self._consistency_proof_timer = None
51+
self._ledger_status_timer = \
52+
RepeatingTimer(self._timer,
53+
self._config.LedgerStatusTimeout * (len(self._provider.all_nodes_names()) - 1),
54+
self._reask_for_ledger_status,
55+
active=False)
56+
self._consistency_proof_timer = \
57+
RepeatingTimer(self._timer,
58+
self._config.ConsistencyProofsTimeout * (len(self._provider.all_nodes_names()) - 1),
59+
self._reask_for_last_consistency_proof,
60+
active=False)
5361

5462
def __repr__(self) -> str:
5563
return "{}:ConsProofService:{}".format(self._provider.node_name(), self._ledger_id)
@@ -432,22 +440,18 @@ def _schedule_reask_cons_proof(self):
432440
)
433441

434442
def _schedule_reask_ledger_status(self):
435-
self._ledger_status_timer = \
436-
RepeatingTimer(self._timer,
437-
self._config.LedgerStatusTimeout * (len(self._provider.all_nodes_names()) - 1),
438-
self._reask_for_ledger_status)
443+
self._ledger_status_timer.update_interval(
444+
self._config.LedgerStatusTimeout * (len(self._provider.all_nodes_names()) - 1))
445+
self._ledger_status_timer.start()
439446

440447
def _schedule_reask_last_cons_proof(self):
441-
if self._consistency_proof_timer is None:
442-
self._consistency_proof_timer = \
443-
RepeatingTimer(self._timer,
444-
self._config.ConsistencyProofsTimeout * (len(self._provider.all_nodes_names()) - 1),
445-
self._reask_for_last_consistency_proof)
448+
self._consistency_proof_timer.update_interval(
449+
self._config.ConsistencyProofsTimeout * (len(self._provider.all_nodes_names()) - 1))
450+
self._consistency_proof_timer.start()
446451

447452
def _cancel_reask(self):
448453
if self._consistency_proof_timer:
449454
self._consistency_proof_timer.stop()
450-
self._consistency_proof_timer = None
451455
if self._ledger_status_timer:
452456
self._ledger_status_timer.stop()
453457
self._timer.cancel(self._request_CPs_if_needed)

0 commit comments

Comments
 (0)