From e34512d0aee436e6716a7cdf11a8a6ec066effbc Mon Sep 17 00:00:00 2001 From: Thomas Kluyver <thomas.kluyver@xfel.eu> Date: Thu, 2 Jan 2025 10:31:23 +0000 Subject: [PATCH] Add some logging around constant injection --- src/cal_tools/constants.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cal_tools/constants.py b/src/cal_tools/constants.py index 25cb9355f..1f8a8a6fd 100644 --- a/src/cal_tools/constants.py +++ b/src/cal_tools/constants.py @@ -1,7 +1,7 @@ import binascii +import logging import time from dataclasses import asdict, dataclass - from datetime import datetime, timezone from hashlib import md5 from pathlib import Path @@ -21,6 +21,8 @@ from cal_tools.calcat_interface2 import ( CONDITION_NAME_MAX_LENGTH = 60 +log = logging.getLogger(__name__) + class InjectionError(Exception): ... @@ -80,7 +82,7 @@ def create_unique_cc_name(det_type, calibration, condition_name): def create_unique_ccv_name(start_idx): # Generate unique name if it doesn't exist - datetime_str = datetime_str = datetime.now( + datetime_str = datetime.now( timezone.utc).strftime('%Y%m%d_%H%M%S') return f'{datetime_str}_sIdx={start_idx}' @@ -243,11 +245,13 @@ def get_or_create_calibration_constant( cc_id = client.get( f"calibrations/{cal_id}/get_calibration_constant", calibration_constant - ) + )['id'] + log.debug("Retrieved existing calibration constant ID %s", cc_id) except CalCatAPIError as e: if e.status_code != 404: raise cc_id = client.post("calibration_constants", calibration_constant)['id'] + log.debug("Created calibration constant ID %s", cc_id) return cc_id @@ -344,6 +348,7 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None): try: condition_id, condition_name = create_condition( client, detector_type, pdu_name, pdu_uuid, cond_params) + log.debug("Condition ID: %s & name: %r", condition_id, condition_name) # Create Calibration Constant in database, if not available. cc_id = get_or_create_calibration_constant( @@ -360,6 +365,7 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None): description="", )) report_id = resp['id'] + log.debug("CalCat report ID: %s", report_id) # Get PDU ID before creating new CCV. pdu_id = client.pdu_by_name(pdu_name)['id'] -- GitLab