-
Notifications
You must be signed in to change notification settings - Fork 731
Expand file tree
/
Copy pathservice_execution.py
More file actions
33 lines (27 loc) · 1.28 KB
/
service_execution.py
File metadata and controls
33 lines (27 loc) · 1.28 KB
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
from decimal import Decimal
from typing import Any
import orjson
from pydantic import BaseModel, Field
from crowdgit.enums import ExecutionStatus, OperationType
class ServiceExecution(BaseModel):
"""Model for creating a new service execution record"""
repo_id: str = Field(..., description="Repository ID")
operation_type: OperationType = Field(..., description="Service operation type")
status: ExecutionStatus = Field(..., description="Execution status")
error_code: str | None = Field(None, description="Custom error code")
error_message: str | None = Field(None, description="Detailed error message")
execution_time_sec: Decimal = Field(..., description="Execution time in seconds")
metrics: dict[str, Any] = Field(
default_factory=dict, description="Service-specific execution metrics"
)
def to_db_dict(self) -> dict[str, Any]:
"""Convert create model to database dictionary"""
return {
"repoId": self.repo_id,
"operationType": self.operation_type.value,
"status": self.status.value,
"errorCode": self.error_code,
"errorMessage": self.error_message,
"executionTimeSec": self.execution_time_sec,
"metrics": orjson.dumps(self.metrics).decode(),
}