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