From b93e5f890ad7d630b118b17c835c3a542af37fbb Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sun, 19 Jan 2025 11:11:38 +0300 Subject: [PATCH] Refactor check_logs function in checker.py to improve subscription message detection. Changed from single match to iterating over all matches, allowing retrieval of the last subscription ID found in logs. Updated logging to reflect the last subscription message or indicate absence, enhancing clarity in log analysis. --- checker.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/checker.py b/checker.py index fdb03be..07f3a25 100644 --- a/checker.py +++ b/checker.py @@ -123,14 +123,18 @@ def check_logs(log_handler): except subprocess.CalledProcessError as e: raise RuntimeError(f"Error running docker logs: {e}") from e - subscription_pattern = r'Ignored subscription creation.*id=(\d+).*err=Subscription completed' - match = re.search(subscription_pattern, log_content) - if match: - subscription_id = match.group(1) - log_handler.info(f"Found subscription completion message, id: {subscription_id}") - return {"status": f"Subscription {subscription_id}"} + subscription_pattern = r'Ignored subscription creation.*id=(\d+)' + matches = re.finditer(subscription_pattern, log_content) + last_id = None - log_handler.info("No subscription completion message found") + for match in matches: + last_id = match.group(1) + + if last_id: + log_handler.info(f"Found last subscription message, id: {last_id}") + return {"status": f"Subscription {last_id}"} + + log_handler.info("No subscription message found") return {"status": "Idle"} if __name__ == "__main__":