2023-02-27 19:51:53 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from typing import List, Optional
|
2023-02-28 17:28:48 +00:00
|
|
|
from pydantic import BaseModel, HttpUrl # pylint: disable=no-name-in-module
|
2023-02-27 19:51:53 +00:00
|
|
|
|
|
|
|
from .build_task import BuildTask
|
|
|
|
from .build_db import BuildDB
|
|
|
|
|
|
|
|
|
|
|
|
class Build(BaseModel):
|
|
|
|
id: int
|
|
|
|
url: HttpUrl
|
|
|
|
build_tasks: List[BuildTask]
|
|
|
|
created_at: datetime
|
|
|
|
finished_at: Optional[datetime] = None
|
|
|
|
|
|
|
|
def as_db_model(self) -> BuildDB:
|
|
|
|
created_at = self.created_at.timestamp()
|
|
|
|
finished_at = self.finished_at.timestamp() \
|
|
|
|
if self.finished_at else None
|
|
|
|
params = {
|
|
|
|
'id': self.id,
|
|
|
|
'url': self.url,
|
|
|
|
'created_at': created_at,
|
|
|
|
'finished_at': finished_at
|
|
|
|
}
|
|
|
|
return BuildDB(**params)
|