From cd6390337c3b53cee0124d301de7146dbdf05988 Mon Sep 17 00:00:00 2001 From: Bram Date: Mon, 7 Jul 2025 15:04:58 +0200 Subject: [PATCH] env for failures --- Dockers/puppeteer-healthcheck/Dockerfile | 1 + Dockers/puppeteer-healthcheck/healthcheck.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockers/puppeteer-healthcheck/Dockerfile b/Dockers/puppeteer-healthcheck/Dockerfile index d4f0442..8f35950 100644 --- a/Dockers/puppeteer-healthcheck/Dockerfile +++ b/Dockers/puppeteer-healthcheck/Dockerfile @@ -23,6 +23,7 @@ ENV TEST_URL="https://www.google.com" ENV API_KEY="Q7Sd#hhFkyHy*T" ENV TARGET_CONTAINER="puppeteer-api" ENV CHECK_INTERVAL=60 +ENV MAX_CONSECUTIVE_FAILURES=3 # Create docker group and user with docker group access RUN groupadd -g 999 docker || true && \ diff --git a/Dockers/puppeteer-healthcheck/healthcheck.py b/Dockers/puppeteer-healthcheck/healthcheck.py index cb3e7b0..f8d7551 100644 --- a/Dockers/puppeteer-healthcheck/healthcheck.py +++ b/Dockers/puppeteer-healthcheck/healthcheck.py @@ -31,6 +31,7 @@ class PuppeteerHealthcheck: self.api_key = os.getenv('API_KEY', 'Q7Sd#hhFkyHy*T') self.target_container = os.getenv('TARGET_CONTAINER', 'puppeteer-api') self.check_interval = int(os.getenv('CHECK_INTERVAL', '60')) + self.max_consecutive_failures = int(os.getenv('MAX_CONSECUTIVE_FAILURES', '3')) # Initialize Docker client with proper error handling self.docker_client = self._initialize_docker_client() @@ -141,7 +142,6 @@ class PuppeteerHealthcheck: logger.info("Starting Puppeteer API healthcheck service") consecutive_failures = 0 - max_consecutive_failures = 3 # Restart after 3 consecutive failures while True: try: @@ -154,7 +154,7 @@ class PuppeteerHealthcheck: logger.warning(f"Health check failed - consecutive failures: {consecutive_failures}") # Restart container if we've had too many consecutive failures - if consecutive_failures >= max_consecutive_failures: + if consecutive_failures >= self.max_consecutive_failures: logger.error(f"Health check failed {consecutive_failures} times consecutively - restarting container") if self.restart_container(): consecutive_failures = 0