Added Ruff linting
This commit is contained in:
1 parent
a96c6db97d
commit
fa9eb3d323
6 files changed
+57
-23
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
[tool.ruff]
|
||||||
|
line-length = 120
|
||||||
|
target-version = "py312"
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = [
|
||||||
|
"E", "F", # pycodestyle errors, pyflakes (unused imports/variables, undefined names)
|
||||||
|
"I", # import sorting (replaces isort)
|
||||||
|
"B", # bugbear: likely bugs
|
||||||
|
"ASYNC", # async mistakes
|
||||||
|
"RUF006", # un-referenced asyncio.create_task (tasks can be garbage-collected)
|
||||||
|
]
|
||||||
|
ignore = ["E501"]
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
known-first-party = ["db_module", "metrics_server", "rabbitmq_handler", "secret_manager",
|
||||||
|
"simple_logger_handler", "uvicorn_logger_config", "validator"]
|
||||||
|
|
||||||
|
[tool.ruff.format]
|
||||||
|
indent-style = "tab"
|
||||||
|
|
||||||
|
[tool.ruff.lint.flake8-bugbear]
|
||||||
|
extend-immutable-calls = [
|
||||||
|
"fastapi.Depends",
|
||||||
|
"fastapi.Query",
|
||||||
|
"fastapi.Header",
|
||||||
|
"fastapi.Body",
|
||||||
|
"fastapi.Security",
|
||||||
|
]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ruff==0.17.0
|
||||||
+5
-3
@@ -1,8 +1,10 @@
|
|||||||
import feedparser
|
|
||||||
from simple_logger_handler import setup_logger
|
|
||||||
import time
|
import time
|
||||||
from urllib.error import URLError
|
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
from urllib.error import URLError
|
||||||
|
|
||||||
|
import feedparser
|
||||||
|
|
||||||
|
from simple_logger_handler import setup_logger
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
|
|
||||||
|
|||||||
+13
-11
@@ -1,14 +1,16 @@
|
|||||||
from fastapi import FastAPI, Depends, HTTPException, Response, Request
|
|
||||||
import uvicorn
|
|
||||||
from contextlib import asynccontextmanager
|
|
||||||
from db_module import get_db, create_connection_pool, close_connection_pool, start_healthcheck_thread
|
|
||||||
from simple_logger_handler import setup_logger, LOG_LEVEL
|
|
||||||
from feed_handler import grab_latest_chapter_information
|
|
||||||
from send_notification import send_notification
|
|
||||||
from metrics_server import REQUEST_COUNTER
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from uvicorn_logger_config import LOGGING_CONFIG
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
|
import uvicorn
|
||||||
|
from fastapi import Depends, FastAPI, HTTPException, Request
|
||||||
|
|
||||||
|
from db_module import close_connection_pool, create_connection_pool, get_db, start_healthcheck_thread
|
||||||
|
from feed_handler import grab_latest_chapter_information
|
||||||
|
from metrics_server import REQUEST_COUNTER
|
||||||
from secret_manager import cleanup_secret_files
|
from secret_manager import cleanup_secret_files
|
||||||
|
from send_notification import send_notification
|
||||||
|
from simple_logger_handler import LOG_LEVEL, setup_logger
|
||||||
|
from uvicorn_logger_config import LOGGING_CONFIG
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
|
|
||||||
@@ -95,11 +97,11 @@ def get_chapters(request: Request, db = Depends(get_db)):
|
|||||||
return {"status": "checked"}
|
return {"status": "checked"}
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error(f"[Royalroad] Failed to fetch feed {royalroadId}: {e}")
|
logger.error(f"[Royalroad] Failed to fetch feed {royalroadId}: {e}")
|
||||||
raise HTTPException(status_code=404, detail=str(e))
|
raise HTTPException(status_code=404, detail=str(e)) from e
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[Royalroad] Error during chapter check: {e}", exc_info=True)
|
logger.error(f"[Royalroad] Error during chapter check: {e}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||||
|
|
||||||
async def start_servers():
|
async def start_servers():
|
||||||
logger.info("[Server] Starting main API (port 5000) and metrics server (port 9000)...")
|
logger.info("[Server] Starting main API (port 5000) and metrics server (port 9000)...")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from fastapi import FastAPI, Response
|
from fastapi import FastAPI, Response
|
||||||
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST, Counter
|
from prometheus_client import CONTENT_TYPE_LATEST, Counter, generate_latest
|
||||||
|
|
||||||
metrics_api = FastAPI(title="Metrics Server", description="Prometheus metrics endpoint")
|
metrics_api = FastAPI(title="Metrics Server", description="Prometheus metrics endpoint")
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import requests
|
|
||||||
from requests.exceptions import RequestException, Timeout, ConnectionError, HTTPError
|
|
||||||
from fastapi import HTTPException
|
|
||||||
from secret_manager import return_credentials
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from simple_logger_handler import setup_logger
|
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from fastapi import HTTPException
|
||||||
|
from requests.exceptions import ConnectionError, HTTPError, RequestException, Timeout
|
||||||
|
|
||||||
|
from secret_manager import return_credentials
|
||||||
|
from simple_logger_handler import setup_logger
|
||||||
|
|
||||||
backend_api_url=os.getenv("BACKEND_API_URL","localhost:8101/internal/receive-notifications")
|
backend_api_url=os.getenv("BACKEND_API_URL","localhost:8101/internal/receive-notifications")
|
||||||
api_key= return_credentials("/etc/secrets/api_key")
|
api_key= return_credentials("/etc/secrets/api_key")
|
||||||
@@ -53,15 +54,15 @@ def send_notification(title: str, chapter_title: str,link: str,max_retries: int
|
|||||||
logger.warning(f"[Notify] Attempt {attempt}/{max_retries} failed: {type(e).__name__}")
|
logger.warning(f"[Notify] Attempt {attempt}/{max_retries} failed: {type(e).__name__}")
|
||||||
if attempt == max_retries:
|
if attempt == max_retries:
|
||||||
logger.error(f"[Notify] All retry attempts failed for '{title}'")
|
logger.error(f"[Notify] All retry attempts failed for '{title}'")
|
||||||
raise HTTPException(status_code=503, detail=f"Notification service unavailable: {type(e).__name__}")
|
raise HTTPException(status_code=503, detail=f"Notification service unavailable: {type(e).__name__}") from e
|
||||||
sleep_time = 2 ** (attempt - 1)
|
sleep_time = 2 ** (attempt - 1)
|
||||||
logger.debug(f"[Notify] Retrying in {sleep_time} seconds...")
|
logger.debug(f"[Notify] Retrying in {sleep_time} seconds...")
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
|
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
logger.error(f"[Notify] HTTP {e.response.status_code}: {e.response.text}")
|
logger.error(f"[Notify] HTTP {e.response.status_code}: {e.response.text}")
|
||||||
raise HTTPException(status_code=e.response.status_code, detail=e.response.text)
|
raise HTTPException(status_code=e.response.status_code, detail=e.response.text) from e
|
||||||
|
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
logger.error(f"[Notify] Unexpected request failure: {e}")
|
logger.error(f"[Notify] Unexpected request failure: {e}")
|
||||||
raise HTTPException(status_code=500, detail=f"Request failed: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"Request failed: {str(e)}") from e
|
||||||
Reference in new issue
Block a user