Docs: Aktualisierung der Dokumentation für Task [31e88f42]
This commit is contained in:
@@ -5,7 +5,7 @@ import requests
|
||||
import json
|
||||
from datetime import datetime
|
||||
from queue_manager import JobQueue
|
||||
from superoffice_client import SuperOfficeClient, ContactNotFoundException
|
||||
from superoffice_client import SuperOfficeClient, ContactNotFoundException, SuperOfficeAuthenticationError
|
||||
from config import settings
|
||||
|
||||
# Setup Logging
|
||||
@@ -75,7 +75,7 @@ def run_worker():
|
||||
status, msg = process_job(job, so_client, queue)
|
||||
|
||||
if status == "RETRY":
|
||||
queue.retry_job_later(job['id'], delay_seconds=120, error_msg=msg)
|
||||
queue.retry_job_later(job['id'], job['retry_count'], delay_seconds=120, error_msg=msg)
|
||||
elif status == "FAILED":
|
||||
queue.fail_job(job['id'], msg or "Job failed status")
|
||||
elif status == "SKIPPED":
|
||||
@@ -104,30 +104,26 @@ def process_job(job, so_client: SuperOfficeClient, queue: JobQueue):
|
||||
payload = job['payload']
|
||||
event_low = job['event_type'].lower()
|
||||
|
||||
# --- 1. HARD ECHO SHIELD (Who triggered this?) ---
|
||||
changed_by = payload.get("ChangedByAssociateId")
|
||||
self_id = job.get('self_associate_id')
|
||||
# --- Strict Whitelist Filter ---
|
||||
# A job is only processed if the webhook indicates a change to a relevant field.
|
||||
# This is the primary defense against noise and echoes.
|
||||
|
||||
if changed_by and self_id and int(changed_by) == int(self_id):
|
||||
msg = f"🛡️ ECHO DETECTED: Event triggered by myself (ID {self_id}). Stopping immediately."
|
||||
logger.info(msg)
|
||||
return ("SKIPPED", msg)
|
||||
|
||||
# --- 2. NOISE REDUCTION: FIELD FILTER (What changed?) ---
|
||||
changes = [c.lower() for c in payload.get("Changes", [])]
|
||||
|
||||
if "person" in event_low:
|
||||
# We allow contact_id changes (linking to company) and basic identity changes
|
||||
if "name" not in changes and "email" not in changes and "jobtitle" not in changes and "contact_id" not in changes:
|
||||
msg = f"Skipping person event: No relevant changes (Name/Email/JobTitle/Mapping) in {changes}."
|
||||
logger.info(f"⏭️ {msg}")
|
||||
return ("SKIPPED", msg)
|
||||
|
||||
elif "contact" in event_low:
|
||||
if "name" not in changes and "urladdress" not in changes:
|
||||
msg = f"Skipping contact event: No relevant changes (Name/Website) in {changes}."
|
||||
logger.info(f"⏭️ {msg}")
|
||||
return ("SKIPPED", msg)
|
||||
# Define fields that are significant enough to trigger a full re-assessment.
|
||||
trigger_fields = ["name", "urladdress", "urls"]
|
||||
|
||||
# The ProgID for the Vertical UDF. A change to this field MUST trigger a resync.
|
||||
vertical_udf_key = settings.UDF_VERTICAL.lower() if settings.UDF_VERTICAL else "superoffice:83"
|
||||
|
||||
# Check if any of the trigger fields or the specific vertical UDF is in the changes list.
|
||||
has_trigger_field = any(f in changes for f in trigger_fields) or vertical_udf_key in changes
|
||||
|
||||
# For '...created' events, we always process. For all other events, we check the whitelist.
|
||||
if "created" not in event_low and not has_trigger_field:
|
||||
msg = f"⏭️ Skipping event '{event_low}': No relevant field changes in {changes}."
|
||||
logger.info(msg)
|
||||
return ("SKIPPED", msg)
|
||||
|
||||
# 0. ID Extraction & Early Exit for irrelevant jobs
|
||||
person_id = None
|
||||
|
||||
Reference in New Issue
Block a user