From f4d841f9f7355dd337f37516a9c1ee6e9eea4dfd Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Sun, 6 Apr 2025 00:39:05 -0400 Subject: [PATCH] update for api timeout --- Dockerfile | 8 +------- api.py | 6 +++--- config.py | 8 ++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72a50338..c2e402ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,24 @@ FROM python:3.9-slim - WORKDIR /app - # Install dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt - # Copy application files COPY main.py config.py api.py state.py ./ COPY missing.py upgrade.py ./ COPY utils/ ./utils/ - # Create state directory RUN mkdir -p /tmp/huntarr-state - # Default environment variables ENV API_KEY="your-api-key" \ API_URL="http://your-sonarr-address:8989" \ + API_TIMEOUT="60" \ HUNT_MISSING_SHOWS=1 \ HUNT_UPGRADE_EPISODES=5 \ SLEEP_DURATION=900 \ STATE_RESET_INTERVAL_HOURS=168 \ RANDOM_SELECTION="true" \ MONITORED_ONLY="true" \ - HUNT_MODE="both" \ DEBUG_MODE="false" - # Run the application CMD ["python", "main.py"] \ No newline at end of file diff --git a/api.py b/api.py index 94893066..a2bf6edf 100644 --- a/api.py +++ b/api.py @@ -7,7 +7,7 @@ Handles all communication with the Sonarr API import requests from typing import List, Dict, Any, Optional, Union from utils.logger import logger, debug_log -from config import API_KEY, API_URL +from config import API_KEY, API_URL, API_TIMEOUT # Create a session for reuse session = requests.Session() @@ -25,9 +25,9 @@ def sonarr_request(endpoint: str, method: str = "GET", data: Dict = None) -> Opt try: if method.upper() == "GET": - response = session.get(url, headers=headers, timeout=30) + response = session.get(url, headers=headers, timeout=API_TIMEOUT) elif method.upper() == "POST": - response = session.post(url, headers=headers, json=data, timeout=30) + response = session.post(url, headers=headers, json=data, timeout=API_TIMEOUT) else: logger.error(f"Unsupported HTTP method: {method}") return None diff --git a/config.py b/config.py index 2b8b3035..1cf631f7 100644 --- a/config.py +++ b/config.py @@ -11,6 +11,13 @@ import logging API_KEY = os.environ.get("API_KEY", "your-api-key") API_URL = os.environ.get("API_URL", "http://your-sonarr-address:8989") +# API timeout in seconds +try: + API_TIMEOUT = int(os.environ.get("API_TIMEOUT", "60")) +except ValueError: + API_TIMEOUT = 60 + print(f"Warning: Invalid API_TIMEOUT value, using default: {API_TIMEOUT}") + # Missing Content Settings try: HUNT_MISSING_SHOWS = int(os.environ.get("HUNT_MISSING_SHOWS", "1")) @@ -53,6 +60,7 @@ def log_configuration(logger): """Log the current configuration settings""" logger.info("=== Huntarr [Sonarr Edition] Starting ===") logger.info(f"API URL: {API_URL}") + logger.info(f"API Timeout: {API_TIMEOUT}s") logger.info(f"Missing Content Configuration: HUNT_MISSING_SHOWS={HUNT_MISSING_SHOWS}") logger.info(f"Upgrade Configuration: HUNT_UPGRADE_EPISODES={HUNT_UPGRADE_EPISODES}") logger.info(f"State Reset Interval: {STATE_RESET_INTERVAL_HOURS} hours")