fix: [30388f42] Maximiere DB-Performance und behebe Locking-Endlosschleife

- Aktiviert den SQLite WAL-Modus für echtes Concurrent Reading/Writing.
- Optimiert get_next_job, um unnötige EXCLUSIVE-Locks zu vermeiden.
- Dies stellt sicher, dass Jobs nach der Verarbeitung korrekt als COMPLETED markiert werden und der Worker nicht in einer Wiederholungsschleife gefangen bleibt.
This commit is contained in:
2026-03-06 14:55:05 +00:00
parent 2783e51f44
commit b9536927f1

View File

@@ -11,6 +11,8 @@ class JobQueue:
def _init_db(self):
with sqlite3.connect(DB_PATH, timeout=30) as conn:
# Enable WAL mode for better concurrency
conn.execute("PRAGMA journal_mode=WAL")
conn.execute("""
CREATE TABLE IF NOT EXISTS jobs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -66,9 +68,6 @@ class JobQueue:
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
# Lock the job
cursor.execute("BEGIN EXCLUSIVE")
try:
cursor.execute("""
SELECT id, event_type, payload, created_at
FROM jobs
@@ -87,14 +86,13 @@ class JobQueue:
(job['id'],)
)
conn.commit()
else:
conn.rollback() # No job found
except Exception:
conn.rollback()
raise
if job:
try:
job['payload'] = json.loads(job['payload'])
except Exception as e:
logger.error(f"Failed to parse payload for job {job['id']}: {e}")
return None
return job