feature: improve admin directory and crawl progress
This commit is contained in:
17
app/services/crawl_control.py
Normal file
17
app/services/crawl_control.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from sqlalchemy import desc, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.config import Settings
|
||||
from app.models import CrawlRun
|
||||
from app.services.crawler import run_crawl
|
||||
|
||||
|
||||
def get_running_run(db: Session) -> CrawlRun | None:
|
||||
return db.scalar(select(CrawlRun).where(CrawlRun.status == "running").order_by(desc(CrawlRun.started_at)).limit(1))
|
||||
|
||||
|
||||
def run_crawl_if_idle(db: Session, settings: Settings) -> tuple[CrawlRun, bool]:
|
||||
running = get_running_run(db)
|
||||
if running:
|
||||
return running, False
|
||||
return run_crawl(db, settings), True
|
||||
Reference in New Issue
Block a user