Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Dec 3, 2024
1 parent cfebe07 commit 67e6f9a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from contextlib import suppress
from typing import TypeAlias

from models_library.clusters import DEFAULT_CLUSTER_ID, ClusterID
from models_library.clusters import ClusterID
from models_library.projects import ProjectID
from models_library.projects_nodes_io import NodeID
from models_library.projects_state import RunningState
Expand Down Expand Up @@ -70,13 +70,6 @@ def convert_result_from_state_type_enum_if_needed(cls, v):
return RunningState(DB_TO_RUNNING_STATE[StateType(v)])
return v

@field_validator("cluster_id", mode="before")
@classmethod
def convert_null_to_default_cluster_id(cls, v):
if v is None:
v = DEFAULT_CLUSTER_ID
return v

@field_validator("created", "modified", "started", "ended")
@classmethod
def ensure_utc(cls, v: datetime.datetime | None) -> datetime.datetime | None:
Expand All @@ -100,7 +93,7 @@ def convert_null_to_empty_metadata(cls, v):
"run_id": 432,
"project_uuid": "65fee9d2-e030-452c-a29c-45d288577ca5",
"user_id": 132,
"cluster_id": 0,
"cluster_id": None,
"iteration": 42,
"result": "UNKNOWN",
"started": None,
Expand All @@ -116,7 +109,7 @@ def convert_null_to_empty_metadata(cls, v):
"run_id": 432,
"project_uuid": "65fee9d2-e030-452c-a29c-45d288577ca5",
"user_id": 132,
"cluster_id": None, # this default to DEFAULT_CLUSTER_ID
"cluster_id": None,
"iteration": 42,
"result": "NOT_STARTED",
"started": None,
Expand All @@ -132,7 +125,7 @@ def convert_null_to_empty_metadata(cls, v):
"run_id": 43243,
"project_uuid": "65fee9d2-e030-452c-a29c-45d288577ca5",
"user_id": 132,
"cluster_id": 123,
"cluster_id": None,
"iteration": 12,
"result": "SUCCESS",
"created": "2021-03-01T13:07:34.191610",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ async def get_or_create_on_demand_cluster(
owner=user_id,
endpoint=returned_cluster.endpoint,
authentication=returned_cluster.authentication,
access_rights={},
)
except RemoteMethodNotRegisteredError as exc:
# no clusters-keeper, that is not going to work!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import networkx as nx
from aiopg.sa import Engine
from fastapi import FastAPI
from models_library.clusters import DEFAULT_CLUSTER_ID
from models_library.projects import ProjectID
from models_library.users import UserID
from servicelib.background_task import start_periodic_task, stop_periodic_task
Expand Down Expand Up @@ -55,7 +54,6 @@ async def run_new_pipeline(
new_run = await CompRunsRepository.instance(db_engine).create(
user_id=user_id,
project_id=project_id,
cluster_id=DEFAULT_CLUSTER_ID,
metadata=run_metadata,
use_on_demand_clusters=use_on_demand_clusters,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

from fastapi import FastAPI
from models_library.docker import DockerGenericTag
Expand All @@ -13,10 +13,10 @@
from models_library.users import UserID
from servicelib.redis import RedisClientSDK
from settings_library.redis import RedisDatabase
from simcore_service_director_v2.modules.redis import get_redis_client_manager

from ...models.comp_runs import Iteration
from ...models.comp_tasks import CompTaskAtDB
from ..redis import get_redis_client_manager

SCHEDULED_STATES: set[RunningState] = {
RunningState.PUBLISHED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import arrow
import sqlalchemy as sa
from aiopg.sa.result import RowProxy
from models_library.clusters import DEFAULT_CLUSTER_ID, ClusterID
from models_library.projects import ProjectID
from models_library.projects_state import RunningState
from models_library.users import UserID
Expand Down Expand Up @@ -43,10 +42,6 @@
("clusters", "cluster_id"),
),
}
_DEFAULT_FK_CONSTRAINT_TO_ERROR: Final[tuple[type[DirectorError], tuple]] = (
DirectorError,
(),
)


class CompRunsRepository(BaseRepository):
Expand Down Expand Up @@ -154,7 +149,6 @@ async def create(
*,
user_id: UserID,
project_id: ProjectID,
cluster_id: ClusterID,
iteration: PositiveInt | None = None,
metadata: RunMetadataDict,
use_on_demand_clusters: bool,
Expand All @@ -178,9 +172,7 @@ async def create(
.values(
user_id=user_id,
project_uuid=f"{project_id}",
cluster_id=(
cluster_id if cluster_id != DEFAULT_CLUSTER_ID else None
),
cluster_id=None,
iteration=iteration,
result=RUNNING_STATE_TO_DB[RunningState.PUBLISHED],
started=datetime.datetime.now(tz=datetime.UTC),
Expand Down
15 changes: 0 additions & 15 deletions services/director-v2/src/simcore_service_director_v2/utils/db.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import logging
from typing import Any

from common_library.serialization import model_dump_with_secrets
from fastapi import FastAPI
from models_library.clusters import BaseCluster
from models_library.projects_state import RunningState
from simcore_postgres_database.models.comp_pipeline import StateType

Expand All @@ -28,17 +25,5 @@
_logger = logging.getLogger(__name__)


def to_clusters_db(cluster: BaseCluster, *, only_update: bool) -> dict[str, Any]:
db_model: dict[str, Any] = model_dump_with_secrets(
cluster,
show_secrets=True,
by_alias=True,
exclude={"id", "access_rights"},
exclude_unset=only_update,
exclude_none=only_update,
)
return db_model


def get_repository(app: FastAPI, repo_type: type[RepoType]) -> RepoType:
return get_base_repository(engine=app.state.engine, repo_type=repo_type)

0 comments on commit 67e6f9a

Please sign in to comment.