-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add validation for messages in the queue - Add queue handlers - Add LongJobStatus - Add last_alive_at to the usage table - Automatically commit the db session
- Loading branch information
1 parent
996a762
commit 5aff60f
Showing
11 changed files
with
243 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""empty message | ||
Revision ID: af57b4dcaecb | ||
Revises: 63a1d1c101bd | ||
Create Date: 2024-06-28 17:43:04.226926 | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "af57b4dcaecb" | ||
down_revision: str | None = "63a1d1c101bd" | ||
branch_labels: str | Sequence[str] | None = None | ||
depends_on: str | Sequence[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column("usage", sa.Column("last_alive_at", sa.DateTime(timezone=True), nullable=False)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("usage", "last_alive_at") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Usage Events schemas.""" | ||
|
||
from datetime import UTC, datetime | ||
from typing import Annotated, Literal | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel, BeforeValidator, Field, validate_call | ||
|
||
from app.constants import LongJobStatus, ServiceType | ||
|
||
# min and max just ensure that the timestamp contains a reasonable value expressed in milliseconds | ||
MIN_TS = datetime(2024, 1, 1, tzinfo=UTC).timestamp() * 1000 | ||
MAX_TS = datetime(2100, 1, 1, tzinfo=UTC).timestamp() * 1000 | ||
|
||
|
||
@validate_call | ||
def _convert_timestamp(value: Annotated[float, Field(gt=MIN_TS, lt=MAX_TS)]) -> datetime: | ||
return datetime.fromtimestamp(value / 1000, tz=UTC) | ||
|
||
|
||
TimeStamp = Annotated[datetime, BeforeValidator(_convert_timestamp)] | ||
|
||
|
||
class StorageUsageEvent(BaseModel): | ||
"""StorageUsageEvent.""" | ||
|
||
type: Literal[ServiceType.STORAGE] | ||
subtype: str | None = None | ||
vlab_id: UUID | ||
proj_id: UUID | ||
job_id: UUID | None | ||
size: int | ||
timestamp: TimeStamp | ||
|
||
|
||
class ShortJobUsageEvent(BaseModel): | ||
"""ShortJobUsageEvent.""" | ||
|
||
type: Literal[ServiceType.SHORT_JOBS] | ||
subtype: str | ||
vlab_id: UUID | ||
proj_id: UUID | ||
job_id: UUID | None | ||
count: int | ||
timestamp: TimeStamp | ||
|
||
|
||
class LongJobUsageEvent(BaseModel): | ||
"""LongJobUsageEvent.""" | ||
|
||
type: Literal[ServiceType.LONG_JOBS] | ||
subtype: str | ||
vlab_id: UUID | ||
proj_id: UUID | ||
job_id: UUID | ||
status: LongJobStatus | ||
instances: int | None = None | ||
instance_type: str | None = None | ||
timestamp: TimeStamp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters