Spaces:
Sleeping
Sleeping
File size: 919 Bytes
01d5a5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
"""
ServerStatus related data transfer objects
"""
from dataclasses import dataclass
from typing import Optional, List
@dataclass
class ProcessInfo:
"""Process Information"""
pid: int # process ID
cpu_percent: float # CPU usage percentage
memory_percent: float # memory usage percentage
create_time: float
cmdline: List[str]
@dataclass
class ServerStatus:
"""server status"""
is_running: bool # if service is running
process_info: Optional[ProcessInfo] = None # process info
@classmethod
def not_running(cls) -> "ServerStatus":
"""create a ServerStatus object representing a not running server"""
return cls(is_running=False)
@classmethod
def running(cls, process_info: ProcessInfo) -> "ServerStatus":
"""create a ServerStatus object representing a running server"""
return cls(is_running=True, process_info=process_info)
|