Add graceful shutdown, logging, streaming with Range Requests, and state.json cache

- Graceful shutdown: SIGTERM/SIGINT handlers stop continuous scraper,
  disconnect Telegram client, drain running jobs with timeout
- Logging: replace print() with logging module throughout web server,
  basicConfig in main.py with structured log format
- Streaming: chunked file reads (64KB) instead of loading entire files
  into memory; full HTTP Range Request support (206 Partial Content)
  for video seeking in the browser
- Cache: TTL-based in-memory cache (1s) for state.json reads in
  StateStore, thread-safe with existing RLock
- Bugfix: send_error_json now converts HTTPStatus to int for JSON
This commit is contained in:
2026-05-27 00:14:26 +02:00
parent 856d04bd16
commit 1dfe41950e
4 changed files with 171 additions and 20 deletions
+4 -1
View File
@@ -1,8 +1,11 @@
import asyncio
import logging
from typing import Any, Dict, List
from app_state import StateStore
logger = logging.getLogger(__name__)
class ScraperJobService:
def __init__(self, state_store: StateStore):
@@ -16,7 +19,7 @@ class ScraperJobService:
state["scrape_media"] = value
self.state_store.update(mutate)
print(f"Media scraping set to {value}")
logger.info("Media scraping set to %s", value)
return
asyncio.run(self._run_async(job_type, payload))