diff --git a/duties/constants/program.py b/duties/constants/program.py index f663b633..17a81287 100644 --- a/duties/constants/program.py +++ b/duties/constants/program.py @@ -1,13 +1,18 @@ """Defines program related constants """ -from helper.kill import GracefulKiller +from math import floor + +from cli.arguments import ARGUMENTS +from helper.terminate import GracefulTerminator REQUEST_TIMEOUT = (3, 5) REQUEST_CONNECTION_ERROR_WAITING_TIME = 2 REQUEST_READ_TIMEOUT_ERROR_WAITING_TIME = 5 PRINTER_TIME_FORMAT = "%M:%S" -GRACEFUL_KILLER = GracefulKiller() +GRACEFUL_TERMINATOR = GracefulTerminator( + floor(ARGUMENTS.mode_cicd_waiting_time / ARGUMENTS.interval) +) THRESHOLD_TO_INFORM_USER_FOR_WAITING_PERIOD = 5000 NOT_ALLOWED_CHARACTERS_FOR_VALIDATOR_PARSING = [".", ","] NUMBER_OF_VALIDATORS_PER_REST_CALL = 1000 diff --git a/duties/main.py b/duties/main.py index 47678bee..d27b73d3 100644 --- a/duties/main.py +++ b/duties/main.py @@ -6,7 +6,7 @@ from typing import Callable, List from cli.arguments import ARGUMENTS -from constants.program import GRACEFUL_KILLER +from constants.program import GRACEFUL_TERMINATOR from fetcher import fetch from fetcher.data_types import DutyType, ValidatorDuty from fetcher.log import log_time_to_next_duties @@ -70,8 +70,9 @@ def __is_current_data_outdated(current_duties: List[ValidatorDuty]) -> bool: if __name__ == "__main__": main_logger = getLogger(__name__) upcoming_duties: List[ValidatorDuty] = [] - while not GRACEFUL_KILLER.kill_now: + while not GRACEFUL_TERMINATOR.kill_now: upcoming_duties = __fetch_validator_duties(upcoming_duties) log_time_to_next_duties(upcoming_duties) + GRACEFUL_TERMINATOR.terminate_in_cicd_mode(ARGUMENTS.mode, upcoming_duties) sleep(ARGUMENTS.interval) main_logger.info("Happy staking. See you for next maintenance \U0001F642 !") diff --git a/duties/protocol/request.py b/duties/protocol/request.py index c15feb52..8f61eaa7 100644 --- a/duties/protocol/request.py +++ b/duties/protocol/request.py @@ -82,7 +82,7 @@ def __send_request( is_request_successful = False response = None calldata = __get_processed_calldata(provided_validators, calldata_type) - while not is_request_successful and not program.GRACEFUL_KILLER.kill_now: + while not is_request_successful and not program.GRACEFUL_TERMINATOR.kill_now: try: match calldata_type: case CalldataType.REQUEST_DATA: