Skip to content

Commit

Permalink
fix(backend): 修复flow的时间戳问题 #3921
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud authored and zhangzhw8 committed Apr 11, 2024
1 parent f47d7ce commit 2b02006
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions dbm-ui/backend/flow/engine/bamboo/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def recursion_nodes_status(self, node: FlowNode, status: str, raw_data: Dict):
for key, values in raw_data.items():
if key == node.node_id:
raw_data[key]["status"] = status
raw_data[key]["created_at"] = datetime2timestamp(node.created_at)
raw_data[key]["started_at"] = datetime2timestamp(node.started_at)
raw_data[key]["updated_at"] = datetime2timestamp(node.updated_at)
raw_data[key]["created_at"] = int(datetime2timestamp(node.created_at))
raw_data[key]["started_at"] = int(datetime2timestamp(node.started_at))
raw_data[key]["updated_at"] = int(datetime2timestamp(node.updated_at))
raw_data[key]["hosts"] = node.hosts
continue

Expand Down
6 changes: 4 additions & 2 deletions dbm-ui/backend/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
specific language governing permissions and limitations under the License.
"""
import datetime
import time
from bisect import bisect_right
from typing import List, Optional, Union

Expand Down Expand Up @@ -91,8 +90,11 @@ def standardized_time_str(datetime_str: str):


def datetime2timestamp(o_datetime: Optional[datetime.datetime]) -> float:
# time.mktime(o_datetime.timetuple())
# 这样转换有问题: time.mktime()函数默认假设时间元组是本地时间,而不是UTC时间。
# 直接用datetime的时间戳转换即可
if o_datetime:
return time.mktime(o_datetime.timetuple())
return o_datetime.timestamp()
return 0.0


Expand Down

0 comments on commit 2b02006

Please sign in to comment.