fix check deployment status bug
This commit is contained in:
parent
43ec8ec01e
commit
217f33fc17
@ -5,14 +5,11 @@ from beanie import Document
|
|||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
from pydantic import Field, field_validator
|
from pydantic import Field, field_validator
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from pymongo import IndexModel
|
||||||
|
|
||||||
|
|
||||||
class Deployment(Document):
|
class Deployment(Document):
|
||||||
deployment_id: str = Field(alias="_id")
|
deployment_id: str
|
||||||
@field_validator("deployment_id", mode="before")
|
|
||||||
@classmethod
|
|
||||||
def convert_object_id(cls, v):
|
|
||||||
return str(v)
|
|
||||||
|
|
||||||
deployment_stage: str
|
deployment_stage: str
|
||||||
deployment_status: Literal["started", "failed", "succeeded", "aborted"]
|
deployment_status: Literal["started", "failed", "succeeded", "aborted"]
|
||||||
@ -35,11 +32,9 @@ class Deployment(Document):
|
|||||||
class Settings:
|
class Settings:
|
||||||
name = "deployment"
|
name = "deployment"
|
||||||
indexes = [
|
indexes = [
|
||||||
[("deployment_product_id", 1), ("created_at", 1)], # Compound index
|
IndexModel([("deployment_product_id", 1), ("created_at", 1)]),
|
||||||
[("deployment_id", 1), ("deployment_status", 1)], # Compound index
|
IndexModel([("deployment_id", 1), ("deployment_status", 1)]),
|
||||||
|
IndexModel([("deployment_id", 1), ("deployment_stage", 1)], unique=True)
|
||||||
# somehow combo + unique errors out
|
|
||||||
# {"keys": [("deployment_id", 1), ("deployment_stage", 1)], "unique": True} # Unique compound index
|
|
||||||
]
|
]
|
||||||
|
|
||||||
class InitDeploymentRequest(BaseModel):
|
class InitDeploymentRequest(BaseModel):
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import uuid
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import List
|
from typing import List
|
||||||
@ -32,12 +33,13 @@ class DeploymentService:
|
|||||||
project_name = "TODO"
|
project_name = "TODO"
|
||||||
|
|
||||||
# retrieve product info
|
# retrieve product info
|
||||||
product_id = "TODO"
|
product_id = request.product_id
|
||||||
product_name = "TODO"
|
product_name = "TODO"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deployment = Deployment.model_construct(
|
deployment = Deployment.model_construct(
|
||||||
|
deployment_id = str(uuid.uuid4()),
|
||||||
deployment_stage = "init",
|
deployment_stage = "init",
|
||||||
deployment_status = "started",
|
deployment_status = "started",
|
||||||
deployment_target_env = request.target_env,
|
deployment_target_env = request.target_env,
|
||||||
@ -74,11 +76,11 @@ class DeploymentService:
|
|||||||
).to_list()
|
).to_list()
|
||||||
grouped = defaultdict(list)
|
grouped = defaultdict(list)
|
||||||
for deployment in deployment_records:
|
for deployment in deployment_records:
|
||||||
grouped[deployment.deployment_product_id].append(deployment)
|
grouped[deployment.deployment_id].append(deployment)
|
||||||
for deployment_list in grouped.values():
|
for deployment_list in grouped.values():
|
||||||
deployment_list.sort(key=lambda d: (d.created_at, d.updated_at), reverse=True)
|
deployment_list.sort(key=lambda d: (d.created_at, d.updated_at), reverse=True)
|
||||||
|
|
||||||
latest_deployments = [deployments[-1] for deployments in grouped.values()]
|
latest_deployments = [deployments[-1] for deployments in grouped.values()]
|
||||||
|
|
||||||
return latest_deployments
|
return latest_deployments
|
||||||
|
|
||||||
async def update_deployment_status(
|
async def update_deployment_status(
|
||||||
@ -117,7 +119,7 @@ class DeploymentService:
|
|||||||
Retrieve git url by product id
|
Retrieve git url by product id
|
||||||
"""
|
"""
|
||||||
# TODO implement this function
|
# TODO implement this function
|
||||||
pass
|
return "TODO-git_url"
|
||||||
|
|
||||||
async def _check_if_project_initialized(
|
async def _check_if_project_initialized(
|
||||||
self,
|
self,
|
||||||
@ -128,7 +130,7 @@ class DeploymentService:
|
|||||||
Check if the project has been initialized
|
Check if the project has been initialized
|
||||||
"""
|
"""
|
||||||
# TODO implement this function
|
# TODO implement this function
|
||||||
pass
|
return True
|
||||||
|
|
||||||
async def _init_product(
|
async def _init_product(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user