Dmitry Beresnev commited on
Commit ·
df070dd
1
Parent(s): 97980d5
fix resources consumption
Browse filesFiles changed (2)
27 unmodified lines28293031323334161 unmodified lines19619719819920020178 unmodified lines280281282283284285286287288234 unmodified lines5235245255265275285295 unmodified lines53553653753853954054127 unmodified lines)from utils.breaking_news_scorer import get_breaking_news_scorerfrom utils.ai_summary_store import init_storage, enqueue_items, fetch_summaries, get_statusfrom utils.ai_summary_worker import start_worker_if_needed# Import news scraperstry:161 unmodified linesif auto_refresh:st.info("⏱️ Auto-refresh enabled (3 min)")st.markdown("---")st.markdown("### 📊 Feed Statistics")78 unmodified lines# Check for forced refresh (don't clear yet - wait until after fetching)force_refresh = st.session_state.get('force_refresh', False)# Initialize AI summary store/worker (shared across sessions/processes)init_storage()start_worker_if_needed()# Fetch news from all sources IN PARALLEL for maximum performanceimport pandas as pd234 unmodified lineswith ThreadPoolExecutor(max_workers=4) as executor:futures_map = {executor.submit(fn): name for fn, name in _fetch_tasks}try:for future in as_completed(futures_map, timeout=90):source_name = futures_map[future]try:result, error = future.result()5 unmodified linescompleted_sources.append(f"{source_name} (error)")status_placeholder.warning(f"⚠️ {source_name} failed, continuing with other sources...")except TimeoutError:fetch_errors.append("⏱️ Some sources timed out after 90 seconds - displaying available results")status_placeholder.warning(f"⚠️ {len(completed_sources)}/{_TOTAL_SOURCES} sources loaded (some timed out)")all_sources = set(futures_map.values())for source in all_sources - set(completed_sources):27 unmodified lines28293031323334161 unmodified lines19619719819920020120220320420520620720820921021121278 unmodified lines291292293294295296297298234 unmodified lines5335345355365375385395 unmodified lines54554654754854955055127 unmodified lines)from utils.breaking_news_scorer import get_breaking_news_scorerfrom utils.ai_summary_store import init_storage, enqueue_items, fetch_summaries, get_statusfrom utils.ai_summary_worker import start_worker_if_needed, is_worker_running# Import news scraperstry:161 unmodified linesif auto_refresh:st.info("⏱️ Auto-refresh enabled (3 min)")st.markdown("---")st.markdown("### 🤖 AI Summary Worker")worker_running = is_worker_running()if worker_running:st.success("● Worker running")else:st.warning("● Worker stopped")if st.button("▶ Start Worker" if not worker_running else "↺ Restart Worker", use_container_width=True):start_worker_if_needed()st.rerun()st.markdown("---")st.markdown("### 📊 Feed Statistics")78 unmodified lines# Check for forced refresh (don't clear yet - wait until after fetching)force_refresh = st.session_state.get('force_refresh', False)# Initialize AI summary store (shared across sessions/processes)init_storage()# Fetch news from all sources IN PARALLEL for maximum performanceimport pandas as pd234 unmodified lineswith ThreadPoolExecutor(max_workers=4) as executor:futures_map = {executor.submit(fn): name for fn, name in _fetch_tasks}try:for future in as_completed(futures_map, timeout=15):source_name = futures_map[future]try:result, error = future.result()5 unmodified linescompleted_sources.append(f"{source_name} (error)")status_placeholder.warning(f"⚠️ {source_name} failed, continuing with other sources...")except TimeoutError:fetch_errors.append("⏱️ Some sources timed out after 15 seconds - displaying available results")status_placeholder.warning(f"⚠️ {len(completed_sources)}/{_TOTAL_SOURCES} sources loaded (some timed out)")all_sources = set(futures_map.values())for source in all_sources - set(completed_sources):
86 unmodified lines8788899091929394959697989910010186 unmodified linesreturn Falsedef start_worker_if_needed():if os.path.exists(PID_FILE):try:with open(PID_FILE, "r", encoding="utf-8") as f:pid = int(f.read().strip() or 0)if pid and _pid_running(pid):returnexcept Exception:passpid = os.fork()if pid != 0:86 unmodified lines8788899091929394959697989910010110210310410510610786 unmodified linesreturn Falsedef is_worker_running() -> bool:"""Return True if the worker process is currently running."""if not os.path.exists(PID_FILE):return Falsetry:with open(PID_FILE, "r", encoding="utf-8") as f:pid = int(f.read().strip() or 0)return bool(pid and _pid_running(pid))except Exception:return Falsedef start_worker_if_needed():if is_worker_running():returnpid = os.fork()if pid != 0:
app/pages/05_Dashboard.py+15-5
app/utils/ai_summary_worker.py+14-8