Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions list_sync/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,28 @@ def init_database():
# Indexes might already exist
pass

# Reconcile orphaned sync_history rows left in_progress by a process that
# was killed/restarted mid-sync (container restart, OOM, crash, etc.).
# Without this, /api/sync/status/live keeps reporting "running" forever
# for a session whose process no longer exists, since nothing else ever
# closes these rows out.
try:
cursor.execute('''
UPDATE sync_history
SET in_progress = 0,
end_time = CURRENT_TIMESTAMP,
status = 'interrupted'
WHERE in_progress = 1 AND end_time IS NULL
''')
if cursor.rowcount:
logging.warning(
f"Reconciled {cursor.rowcount} orphaned sync_history row(s) "
"left in_progress by a previous process that didn't exit cleanly"
)
except sqlite3.OperationalError:
# Table may not exist yet on a brand new database; nothing to reconcile
pass

# Overseerr users table - stores synced Overseerr users
cursor.execute('''
CREATE TABLE IF NOT EXISTS overseerr_users (
Expand Down