albs_analytics/build_analitycs/build_analytics/models/build_task.py
2023-02-27 20:51:53 +01:00

32 lines
866 B
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel
from .build_task_db import BuildTaskDB
from .enums import ArchEnum
class BuildTask(BaseModel):
id: int
build_id: int
arch: str
started_at: Optional[datetime] = None
finished_at: Optional[datetime] = None
status_id: int
def as_db_model(self) -> BuildTaskDB:
started_at = self.started_at.timestamp() \
if self.started_at else None
finished_at = self.finished_at.timestamp() \
if self.finished_at else None
params = {
'id': self.id,
'build_id': self.build_id,
'arch_id': ArchEnum[self.arch].value,
'started_at': started_at,
'finished_at': finished_at,
'status_id': self.status_id
}
return BuildTaskDB(**params)