From 605d840a76a86615d8b3439d8f90ab759f31d223 Mon Sep 17 00:00:00 2001 From: "It's me, CI" Date: Thu, 15 Feb 2024 15:02:58 +0100 Subject: [PATCH] Separate the main loop from the setup. --- .../coordinator/coordinator.py | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/uptime_service_validation/coordinator/coordinator.py b/uptime_service_validation/coordinator/coordinator.py index f2bff16..ba294a4 100644 --- a/uptime_service_validation/coordinator/coordinator.py +++ b/uptime_service_validation/coordinator/coordinator.py @@ -22,30 +22,7 @@ sys.path.insert(0, project_root) -def main(): - process_loop_count = 0 - load_dotenv() - - logging.basicConfig( - stream=sys.stdout, - level=logging.INFO, - format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", - ) - - connection = psycopg2.connect( - host=os.environ["POSTGRES_HOST"], - port=os.environ["POSTGRES_PORT"], - database=os.environ["POSTGRES_DB"], - user=os.environ["POSTGRES_USER"], - password=os.environ["POSTGRES_PASSWORD"], - ) - - # Step 1 Get previous record and build relations list - interval = int(os.environ["SURVEY_INTERVAL_MINUTES"]) - prev_batch_end, cur_batch_end, bot_log_id = getBatchTimings( - connection, logging, interval - ) - +def process(connection, prev_batch_end, cur_batch_end, bot_log_id): while True: cur_timestamp = datetime.now(timezone.utc) logging.info( @@ -307,6 +284,31 @@ def main(): cur_timestamp, ) +def main(): + process_loop_count = 0 + load_dotenv() + + logging.basicConfig( + stream=sys.stdout, + level=logging.INFO, + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", + ) + + connection = psycopg2.connect( + host=os.environ["POSTGRES_HOST"], + port=os.environ["POSTGRES_PORT"], + database=os.environ["POSTGRES_DB"], + user=os.environ["POSTGRES_USER"], + password=os.environ["POSTGRES_PASSWORD"], + ) + + # Step 1 Get previous record and build relations list + interval = int(os.environ["SURVEY_INTERVAL_MINUTES"]) + prev_batch_end, cur_batch_end, bot_log_id = getBatchTimings( + connection, logging, interval + ) + process(connection, prev_batch_end, cur_batch_end, bot_log_id) + if __name__ == "__main__": main()