|
1 | 1 | """ORM Models for v2 tables and objects.""" |
2 | 2 |
|
3 | | -from datetime import datetime |
| 3 | +from collections.abc import MutableSequence |
4 | 4 | from typing import Any |
5 | 5 | from uuid import NAMESPACE_DNS, UUID, uuid4, uuid5 |
6 | 6 |
|
7 | | -from pydantic import AliasChoices, ValidationInfo, model_validator |
| 7 | +from pydantic import AliasChoices, AwareDatetime, ValidationInfo, model_validator |
8 | 8 | from sqlalchemy.dialects import postgresql |
9 | 9 | from sqlalchemy.ext.mutable import MutableDict, MutableList |
10 | 10 | from sqlalchemy.types import PickleType |
@@ -99,6 +99,20 @@ class CampaignUpdate(BaseSQLModel): |
99 | 99 | status: StatusField | None = None |
100 | 100 |
|
101 | 101 |
|
| 102 | +class CampaignSummary(CampaignBase): |
| 103 | + """Model for the response of a Campaign Summary route.""" |
| 104 | + |
| 105 | + node_summary: MutableSequence["NodeStatusSummary"] |
| 106 | + |
| 107 | + |
| 108 | +class NodeStatusSummary(BaseSQLModel): |
| 109 | + """Model for a Node Status Summary.""" |
| 110 | + |
| 111 | + status: StatusField = Field(description="A state name") |
| 112 | + count: int = Field(description="Count of nodes in this state") |
| 113 | + mtime: AwareDatetime | None = Field(description="The most recent update time for nodes in this state") |
| 114 | + |
| 115 | + |
102 | 116 | class NodeBase(BaseSQLModel): |
103 | 117 | """nodes_v2 db table""" |
104 | 118 |
|
@@ -212,17 +226,17 @@ class Task(BaseSQLModel, table=True): |
212 | 226 | namespace: UUID = Field(foreign_key="campaigns_v2.id", description="The ID of a Campaign") |
213 | 227 | node: UUID = Field(foreign_key="nodes_v2.id", description="The ID of the target node") |
214 | 228 | priority: int | None = Field(default=None) |
215 | | - created_at: datetime = Field( |
| 229 | + created_at: AwareDatetime = Field( |
216 | 230 | description="The `datetime` (UTC) at which this Task was first added to the queue", |
217 | 231 | default_factory=now_utc, |
218 | 232 | sa_column=Column(DateTime(timezone=True)), |
219 | 233 | ) |
220 | | - submitted_at: datetime | None = Field( |
| 234 | + submitted_at: AwareDatetime | None = Field( |
221 | 235 | description="The `datetime` (UTC) at which this Task was first submitted as work to the event loop", |
222 | 236 | default=None, |
223 | 237 | sa_column=Column(DateTime(timezone=True)), |
224 | 238 | ) |
225 | | - finished_at: datetime | None = Field( |
| 239 | + finished_at: AwareDatetime | None = Field( |
226 | 240 | description=( |
227 | 241 | "The `datetime` (UTC) at which this Task successfully finalized. " |
228 | 242 | "A Task whose `finished_at` is not `None` is tombstoned and is subject to deletion." |
@@ -251,12 +265,12 @@ class ActivityLogBase(BaseSQLModel): |
251 | 265 | namespace: UUID = Field(foreign_key="campaigns_v2.id", description="The ID of a Campaign") |
252 | 266 | node: UUID | None = Field(default=None, foreign_key="nodes_v2.id", description="The ID of a Node") |
253 | 267 | operator: str = Field(description="The name of the operator or pilot who triggered the activity") |
254 | | - created_at: datetime = Field( |
| 268 | + created_at: AwareDatetime = Field( |
255 | 269 | description="The `datetime` in UTC at which this log entry was created.", |
256 | 270 | default_factory=now_utc, |
257 | 271 | sa_column=Column(DateTime(timezone=True)), |
258 | 272 | ) |
259 | | - finished_at: datetime | None = Field( |
| 273 | + finished_at: AwareDatetime | None = Field( |
260 | 274 | description="The `datetime` in UTC at which this log entry was finalized.", |
261 | 275 | default=None, |
262 | 276 | sa_column=Column(DateTime(timezone=True), nullable=True), |
|
0 commit comments