as_utils.py 1.1 KB

123456789101112131415161718192021222324252627
  1. import datetime
  2. def get_formatted_timestamp():
  3. """
  4. 获取指定格式的时间戳: YYYY-MM-DD HH:MM:SS,ms
  5. 例如: 2025-05-16 14:44:09,324
  6. """
  7. now = datetime.datetime.now()
  8. # 格式化日期和时间部分
  9. timestamp_str = now.strftime("%Y-%m-%d %H:%M:%S")
  10. # 获取毫秒部分,并格式化为3位数字
  11. milliseconds = now.microsecond // 1000
  12. milliseconds_str = f"{milliseconds:03d}"
  13. # 组合最终格式
  14. return f"{timestamp_str},{milliseconds_str}"
  15. def add_state_flow_entry(process_item, state_name, msg, status_val="pending"):
  16. """辅助函数,用于向 stateFlow 列表添加条目。"""
  17. entry = {
  18. "stateName": state_name, # 状态名称
  19. "timestamp": get_formatted_timestamp(), # 时间戳
  20. "msg": msg, # 消息
  21. "status": status_val # 状态值: "pending", "success", "fail", "skipped"
  22. }
  23. process_item["stateFlow"].append(entry)
  24. process_item["currentState"] = state_name # 更新整体状态
  25. # logging.info(f"[流程 {process_item.get('id', 'N/A')}][{state_name}]: {msg} (状态: {status_val})")