logging for debug purposes

This commit is contained in:
Daniel Roth 2026-07-08 16:02:33 +00:00
parent 31fc7ee115
commit 0306b43584

View file

@ -5,6 +5,9 @@ from backend.app.db.models.hubspot_deal_data import HubspotDealData
from domain.abri.models import UNSUCCESSFUL_OUTCOMES
from etl.hubspot.project_data import ProjectData
from etl.hubspot.utils import parse_hs_bool, parse_hs_date, parse_hs_int
from utilities.logger import setup_logger
logger = setup_logger()
class HubspotDealDiffer:
@ -192,6 +195,13 @@ class HubspotDealDiffer:
new_listing: Optional[Dict[str, str]],
old_deal: HubspotDealData,
) -> Optional[Dict[str, Any]]:
logger.info(
"Evaluating Abri triggers for HubSpot deal %s "
"(project_code=%r, associated_project_id=%s)",
hubspot_deal_id,
new_deal.get("project_code"),
new_project["project_id"] if new_project is not None else None,
)
flows: List[str] = []
if HubspotDealDiffer.check_for_abri_job_amendment(
new_deal=new_deal, new_project=new_project, old_deal=old_deal
@ -211,8 +221,15 @@ class HubspotDealDiffer:
flows.append("abandon_job")
if not flows:
logger.info(
"No Abri flows triggered for HubSpot deal %s", hubspot_deal_id
)
return None
logger.info(
"Abri flows triggered for HubSpot deal %s: %s", hubspot_deal_id, flows
)
confirmed_survey_date = parse_hs_date(new_deal.get("confirmed_survey_date"))
last_submission_date = parse_hs_date(new_deal.get("last_submission_date"))
listing = new_listing or {}
@ -248,10 +265,19 @@ class HubspotDealDiffer:
if not HubspotDealDiffer._is_abri_condition_deal(new_deal, new_project):
return False
new_survey_date = parse_hs_date(new_deal.get("confirmed_survey_date"))
logger.info(
"Abri job-logging check: old_confirmed_survey_date=%s "
"new_confirmed_survey_date=%s",
old_deal.confirmed_survey_date,
new_survey_date,
)
# Only a first-time survey date (previously empty) logs a new job.
if old_deal.confirmed_survey_date is not None:
return False
return parse_hs_date(new_deal.get("confirmed_survey_date")) is not None
return new_survey_date is not None
@staticmethod
def check_for_abri_job_amendment(
@ -285,10 +311,21 @@ class HubspotDealDiffer:
if not HubspotDealDiffer._is_abri_condition_deal(new_deal, new_project):
return False
new_commencement_date = parse_hs_date(
new_deal.get("expected_commencement_date")
)
logger.info(
"Abri tenant-data-fetch check: old_commencement_date=%s "
"new_commencement_date=%s",
old_deal.expected_commencement_date,
new_commencement_date,
)
# Only a first-time commencement date (previously empty) fires the fetch.
if old_deal.expected_commencement_date is not None:
return False
return parse_hs_date(new_deal.get("expected_commencement_date")) is not None
return new_commencement_date is not None
@staticmethod
def check_for_abri_deal_abandonment(
@ -334,10 +371,18 @@ class HubspotDealDiffer:
new_deal: Dict[str, str], new_project: Optional[ProjectData]
) -> bool:
if new_project is not None:
return (
is_match = (
new_project["project_id"]
== HubspotDealDiffer.ABRI_CONDITION_ASSOCIATED_PROJECT_ID
)
logger.info(
"Abri condition-deal check via associated project: "
"project_id=%s expected=%s match=%s",
new_project["project_id"],
HubspotDealDiffer.ABRI_CONDITION_ASSOCIATED_PROJECT_ID,
is_match,
)
return is_match
# TEST_ABRI_PROJECT_CODE_OVERRIDE lets a non-production deploy fire on a
# sandbox deal's own project code; unset (the production default) falls
@ -347,7 +392,15 @@ class HubspotDealDiffer:
or HubspotDealDiffer.ABRI_CONDITION_PROJECT_CODE
)
new_project_code = (new_deal.get("project_code") or "").lower()
return new_project_code == expected_code.lower()
is_match = new_project_code == expected_code.lower()
logger.info(
"Abri condition-deal check via project_code: "
"new_project_code=%r expected=%r match=%s",
new_project_code,
expected_code.lower(),
is_match,
)
return is_match
@staticmethod
def _has_valid_pashub_link(new_pashub_link: str) -> bool: