2023-02-27 19:51:53 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from typing import Optional
|
|
|
|
|
2023-02-28 17:28:48 +00:00
|
|
|
from pydantic import BaseModel # pylint: disable=no-name-in-module
|
2023-02-27 19:51:53 +00:00
|
|
|
|
|
|
|
from .build_task_db import BuildTaskDB
|
|
|
|
from .enums import ArchEnum
|
|
|
|
|
|
|
|
|
|
|
|
class BuildTask(BaseModel):
|
|
|
|
id: int
|
2023-03-01 13:13:14 +00:00
|
|
|
name: str
|
2023-02-27 19:51:53 +00:00
|
|
|
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,
|
2023-03-01 13:13:14 +00:00
|
|
|
'name': self.name,
|
2023-02-27 19:51:53 +00:00
|
|
|
'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)
|