INNER CODE UNIT · Python
startup
iLearn-Lab/NovelClaw · apps/multiagent/local_web_portal/app/main.py:100
def startup() -> None:
Base.metadata.create_all(bind=engine)
# Detached job launchers send periodic heartbeats while work is active.
# If the heartbeat stops past the cutoff, the job is treated as stale.
with SessionLocal() as db:
now = datetime.now(timezone.utc)
running_cutoff = now - timedelta(seconds=max(60, settings.startup_recovery_seconds))
queued_cutoff = now - timedelta(seconds=max(60, settings.stale_queued_seconds))
stale_running_jobs = db.execute(
select(GenerationJob).where(
GenerationJob.status == "running",
GenerationJob.updated_at < running_cutoff,
)
).scalars().all()
stale_queued_jobs = db.execute(
select(GenerationJob).where(
GenerationJob.status == "queued",