Fix the time counter for the each step and the playbook

This commit is contained in:
2026-07-25 15:54:16 +01:00
parent 7918977279
commit 1acb32a074
+6 -9
View File
@@ -7,9 +7,8 @@ import json
import time import time
import datetime import datetime
import importlib.util import importlib.util
from os import error, name from typing import Dict, List, Any, Optional
from typing import Callable, Dict, List, Any, Optional from dataclasses import dataclass
from dataclasses import dataclass, field
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from playbook.models import Status, StepLog from playbook.models import Status, StepLog
@@ -48,7 +47,7 @@ class StepIF(ABC):
def run(self, name: str) -> StepLog: def run(self, name: str) -> StepLog:
""" Run the step. """ """ Run the step. """
start_time: float = datetime.datetime.now().timestamp() start_time: int = time.perf_counter_ns()
substeps: List[StepLog] = [] substeps: List[StepLog] = []
status: Status = Status.GOOD status: Status = Status.GOOD
@@ -61,8 +60,7 @@ class StepIF(ABC):
if status == Status.BAD: if status == Status.BAD:
break break
end_time: float = datetime.datetime.now().timestamp() delta: int = time.perf_counter_ns() - start_time
delta: int = int(end_time - start_time)
errors = [] errors = []
msg: str = "" msg: str = ""
@@ -178,7 +176,7 @@ class Play(object):
return json.dumps(data) return json.dumps(data)
def play(self) -> StepLog: def play(self) -> StepLog:
start_time: float = datetime.datetime.now().timestamp() start_time: int = time.perf_counter_ns()
playLog: StepLog = StepLog( playLog: StepLog = StepLog(
step_name=self.name, step_name=self.name,
status=Status.GOOD, status=Status.GOOD,
@@ -198,8 +196,7 @@ class Play(object):
playLog.status = Status.BAD playLog.status = Status.BAD
break break
end_time: float = datetime.datetime.now().timestamp() delta: int = time.perf_counter_ns() - start_time
delta: int = int(end_time - start_time)
playLog.duration_sec = delta playLog.duration_sec = delta
if playLog.status == Status.GOOD: if playLog.status == Status.GOOD: