Skip to content

Commit

Permalink
feat(db-init): separate database initialization from global database …
Browse files Browse the repository at this point in the history
…session (#1805)
  • Loading branch information
mabw-rte committed Nov 23, 2023
1 parent 4481c81 commit 6a5c49d
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 371 deletions.
19 changes: 17 additions & 2 deletions antarest/core/tasks/model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import uuid
from datetime import datetime
from enum import Enum
from typing import Any, List, Optional
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Extra
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, Sequence, String # type: ignore
from sqlalchemy.orm import relationship # type: ignore
from sqlalchemy.engine.base import Engine # type: ignore
from sqlalchemy.orm import Session, relationship, sessionmaker # type: ignore

from antarest.core.persistence import Base

Expand Down Expand Up @@ -171,3 +172,17 @@ def __repr__(self) -> str:
f" result_msg={self.result_msg},"
f" result_status={self.result_status}"
)


def cancel_orphan_tasks(engine: Engine, session_args: Dict[str, bool]) -> None:
updated_values = {
TaskJob.status: TaskStatus.FAILED.value,
TaskJob.result: False,
TaskJob.result_msg: "Task was interrupted due to server restart",
TaskJob.completion_date: datetime.utcnow(),
}
with sessionmaker(bind=engine, **session_args)() as session:
session.query(TaskJob).filter(TaskJob.status.in_([TaskStatus.RUNNING.value, TaskStatus.PENDING.value])).update(
updated_values, synchronize_session=False
)
session.commit()
2 changes: 1 addition & 1 deletion antarest/login/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def build_login(
"""

if service is None:
user_repo = UserRepository(config)
user_repo = UserRepository()
bot_repo = BotRepository()
group_repo = GroupRepository()
role_repo = RoleRepository()
Expand Down
Loading

0 comments on commit 6a5c49d

Please sign in to comment.