Dmitry Beresnev commited on
Commit ·
df070dd
1
Parent(s): 97980d5
fix resources consumption
Browse filesFiles changed (2)
27 unmodified lines2829303131323334161 unmodified lines19619719819920020120220320420520620720820921021121278 unmodified lines291292293283294295285296297298234 unmodified lines5335345355265365375385395 unmodified lines54554654753854854955055127 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_neededfrom utils.ai_summary_worker import start_worker_if_needed, is_worker_running
# Import news scraperstry:161 unmodified lines if 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/worker (shared across sessions/processes)# Initialize AI summary store (shared across sessions/processes)init_storage()start_worker_if_needed()
# Fetch news from all sources IN PARALLEL for maximum performanceimport pandas as pd234 unmodified lines with 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): for future in as_completed(futures_map, timeout=15): source_name = futures_map[future] try: result, error = future.result()5 unmodified lines completed_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") 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 lines87888990919293949596979899100101102919293949596103104979810510610786 unmodified lines return False
def is_worker_running() -> bool: """Return True if the worker process is currently running.""" if not os.path.exists(PID_FILE): return False try: 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 False
def 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): return if is_worker_running(): return except Exception: pass
pid = os.fork() if pid != 0:app/pages/05_Dashboard.py+15-5
app/utils/ai_summary_worker.py+14-8