[30388f42] fix: correct indentation error in queue_manager.py

This commit is contained in:
2026-03-10 19:38:55 +00:00
parent 87c710a3e9
commit 9f943aea21

View File

@@ -66,47 +66,47 @@ class JobQueue:
conn.commit() conn.commit()
logger.debug(f"Job added: {event_type} for entity {entity_id}") logger.debug(f"Job added: {event_type} for entity {entity_id}")
except Exception as e: except Exception as e:
logger.error(f"❌ Failed to add job: {e}", exc_info=True) logger.error(f"❌ Failed to add job: {e}", exc_info=True)
conn.rollback() conn.rollback()
raise raise
def is_duplicate_pending(self, event_type: str, payload: dict) -> bool: def is_duplicate_pending(self, event_type: str, payload: dict) -> bool:
""" """
Checks if a job with the same event_type and entity_id is already PENDING. Checks if a job with the same event_type and entity_id is already PENDING.
This is to prevent adding duplicate jobs from webhooks that are sent multiple times. This is to prevent adding duplicate jobs from webhooks that are sent multiple times.
""" """
# We only want to de-duplicate creation events, as change events can be validly stacked. # We only want to de-duplicate creation events, as change events can be validly stacked.
if "created" not in event_type.lower(): if "created" not in event_type.lower():
return False return False
entity_id = payload.get("PrimaryKey") entity_id = payload.get("PrimaryKey")
if not entity_id: if not entity_id:
return False # Cannot de-duplicate without a key return False # Cannot de-duplicate without a key
five_minutes_ago = datetime.utcnow() - timedelta(minutes=5) five_minutes_ago = datetime.utcnow() - timedelta(minutes=5)
with sqlite3.connect(DB_PATH, timeout=30) as conn: with sqlite3.connect(DB_PATH, timeout=30) as conn:
try: try:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(""" cursor.execute("""
SELECT id FROM jobs SELECT id FROM jobs
WHERE event_type = ? WHERE event_type = ?
AND entity_id = ? AND entity_id = ?
AND status = 'PENDING' AND status = 'PENDING'
AND created_at >= ? AND created_at >= ?
""", (event_type, entity_id, five_minutes_ago)) """, (event_type, entity_id, five_minutes_ago))
if existing_job := cursor.fetchone(): if existing_job := cursor.fetchone():
logger.warning(f"Found PENDING duplicate of job {existing_job[0]} for event '{event_type}' and entity '{entity_id}'. Ignoring new webhook.") logger.warning(f"Found PENDING duplicate of job {existing_job[0]} for event '{event_type}' and entity '{entity_id}'. Ignoring new webhook.")
return True return True
return False return False
except Exception as e: except Exception as e:
logger.error(f"❌ Failed to check for PENDING duplicate jobs for entity '{entity_id}': {e}", exc_info=True) logger.error(f"❌ Failed to check for PENDING duplicate jobs for entity '{entity_id}': {e}", exc_info=True)
return False # Fail safe: better to have a duplicate than to miss an event. return False # Fail safe: better to have a duplicate than to miss an event.
def update_entity_name(self, job_id, name, associate_name=None): def update_entity_name(self, job_id, name, associate_name=None):
with sqlite3.connect(DB_PATH, timeout=30) as conn: with sqlite3.connect(DB_PATH, timeout=30) as conn:
try: try:
if associate_name: if associate_name:
conn.execute( conn.execute(
"UPDATE jobs SET entity_name = ?, associate_name = ?, updated_at = datetime('now') WHERE id = ?", "UPDATE jobs SET entity_name = ?, associate_name = ?, updated_at = datetime('now') WHERE id = ?",
(str(name), str(associate_name), job_id) (str(name), str(associate_name), job_id)