зеркало из https://github.com/microsoft/lisa.git
add action message
This commit is contained in:
Родитель
a477e47c15
Коммит
c0d361e930
|
@ -1,8 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
from lisa import notifier
|
||||
from lisa.util import LisaException
|
||||
from lisa.util.logger import get_logger
|
||||
from lisa.util.perf_timer import create_timer
|
||||
|
@ -24,6 +26,14 @@ ActionStatus = Enum(
|
|||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ActionMessage(notifier.MessageBase):
|
||||
type: str = "Action"
|
||||
sub_type: str = ""
|
||||
status: ActionStatus = ActionStatus.UNKNOWN
|
||||
total_elapsed: float = 0
|
||||
|
||||
|
||||
class Action(metaclass=ABCMeta):
|
||||
def __init__(self) -> None:
|
||||
self.name: str = self.__class__.__name__
|
||||
|
@ -32,6 +42,7 @@ class Action(metaclass=ABCMeta):
|
|||
self.__status = ActionStatus.UNINITIALIZED
|
||||
self.__is_started = False
|
||||
self.__timer = create_timer()
|
||||
self.__total: float = 0
|
||||
|
||||
@abstractmethod
|
||||
async def start(self) -> None:
|
||||
|
@ -55,6 +66,14 @@ class Action(metaclass=ABCMeta):
|
|||
f"{self.name} status changed from {self.__status.name} "
|
||||
f"to {status.name} with {self.__timer}"
|
||||
)
|
||||
self.__total += self.__timer.elapsed()
|
||||
message = ActionMessage(
|
||||
elapsed=self.__timer.elapsed(),
|
||||
sub_type=self.name,
|
||||
status=status,
|
||||
total_elapsed=self.__total,
|
||||
)
|
||||
notifier.notify(message=message)
|
||||
self.__timer = create_timer()
|
||||
self.__status = status
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче