Fix TaskBeat: add live stuck-task watchdog (auto-reset in_progress > 5min every beat cycle)
This commit is contained in:
parent
0be80c5ee1
commit
ad7c1bdddc
1 changed files with 20 additions and 0 deletions
20
app.py
20
app.py
|
|
@ -2269,6 +2269,26 @@ def process_beat_tasks():
|
|||
|
||||
while True:
|
||||
try:
|
||||
# Stuck-Task-Watchdog: in_progress Tasks älter als 5 min zurücksetzen
|
||||
try:
|
||||
con = sqlite3.connect(EMAIL_JOURNAL_DB)
|
||||
stuck = con.execute(
|
||||
"SELECT id, title FROM tasks WHERE status='in_progress' "
|
||||
"AND datetime(created_at) < datetime('now', '-5 minutes')"
|
||||
).fetchall()
|
||||
if stuck:
|
||||
ids = [r[0] for r in stuck]
|
||||
con.execute(
|
||||
f"UPDATE tasks SET status='pending' WHERE id IN ({','.join('?'*len(ids))})",
|
||||
ids
|
||||
)
|
||||
con.commit()
|
||||
for r in stuck:
|
||||
logger.warning("[TaskBeat] Stuck Task #%d zurückgesetzt: %s", r[0], r[1][:60])
|
||||
con.close()
|
||||
except Exception as e:
|
||||
logger.error("[TaskBeat] Watchdog-Fehler: %s", str(e))
|
||||
|
||||
# Lade pending Tasks aus Datenbank
|
||||
db_tasks = get_tasks(status='pending')
|
||||
# Konvertiere zu Dict-Format für Legacy-Kompatibilität
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue