Recover transient Syncthing and SQLite job failures
This commit is contained in:
@@ -671,6 +671,15 @@ class ClientJobExecutor:
|
||||
# Syncthing can expose the per-job directory before the
|
||||
# ready marker and manifest have arrived atomically as a set.
|
||||
pass
|
||||
except RouteSetupError as exc:
|
||||
# A network interruption can temporarily make the local
|
||||
# Syncthing REST API unavailable. The staged payload is
|
||||
# durable and the job must remain recoverable; keep polling
|
||||
# instead of turning a transient outage into a failed job.
|
||||
logger.warning("syncthing_status_deferred", extra={
|
||||
"job_id": definition.job_id,
|
||||
"error_type": type(exc).__name__,
|
||||
})
|
||||
time.sleep(self.poll_interval)
|
||||
|
||||
def _target_materialize(
|
||||
|
||||
@@ -7,6 +7,8 @@ import json
|
||||
import os
|
||||
import sqlite3
|
||||
import stat
|
||||
import threading
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
@@ -14,6 +16,12 @@ from pathlib import Path
|
||||
SCHEMA_VERSION = 3
|
||||
|
||||
|
||||
# A client daemon executes unrelated jobs concurrently. SQLite still permits
|
||||
# only one writer, so serialize this process's short state transactions rather
|
||||
# than allowing an otherwise healthy job to fail after its busy timeout.
|
||||
_DATABASE_LOCK = threading.RLock()
|
||||
|
||||
|
||||
class CommandConflict(RuntimeError):
|
||||
pass
|
||||
|
||||
@@ -557,14 +565,30 @@ class ClientStore:
|
||||
).fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
|
||||
def _connect(self) -> sqlite3.Connection:
|
||||
connection = sqlite3.connect(self.database, isolation_level=None, timeout=5)
|
||||
connection.row_factory = sqlite3.Row
|
||||
connection.execute("PRAGMA foreign_keys = ON")
|
||||
connection.execute("PRAGMA journal_mode = WAL")
|
||||
connection.execute("PRAGMA synchronous = FULL")
|
||||
connection.execute("PRAGMA busy_timeout = 5000")
|
||||
return connection
|
||||
@contextmanager
|
||||
def _connect(self):
|
||||
"""Yield one connection while serializing local SQLite writers.
|
||||
|
||||
The longer SQLite timeout also covers a short lock held by a separate
|
||||
maintenance process such as a backup. The lock is deliberately held
|
||||
for the full transaction, including ``BEGIN IMMEDIATE``.
|
||||
"""
|
||||
with _DATABASE_LOCK:
|
||||
connection = sqlite3.connect(
|
||||
self.database, isolation_level=None, timeout=30
|
||||
)
|
||||
try:
|
||||
connection.row_factory = sqlite3.Row
|
||||
connection.execute("PRAGMA foreign_keys = ON")
|
||||
connection.execute("PRAGMA journal_mode = WAL")
|
||||
connection.execute("PRAGMA synchronous = FULL")
|
||||
connection.execute("PRAGMA busy_timeout = 30000")
|
||||
# Preserve the original ``with connection`` commit/rollback
|
||||
# behavior used by every store operation.
|
||||
with connection:
|
||||
yield connection
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
|
||||
def _canonical(value: object) -> str:
|
||||
|
||||
Reference in New Issue
Block a user