-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3215aa5
commit 078dd4a
Showing
2 changed files
with
65 additions
and
21 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,53 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List, Any | ||
from pydantic import BaseModel | ||
from sqlalchemy import Engine, Table | ||
from autosubmit_api.database import tables | ||
from autosubmit_api.database.common import ( | ||
create_sqlite_db_engine, | ||
) | ||
from autosubmit_api.persistance.experiment import ExperimentPaths | ||
|
||
|
||
class JobPackageModel(BaseModel): | ||
exp_id: Any | ||
package_name: Any | ||
job_name: Any | ||
|
||
|
||
class JobPackagesRepository(ABC): | ||
@abstractmethod | ||
def get_all(self) -> List[JobPackageModel]: | ||
""" | ||
Get all job packages. | ||
""" | ||
|
||
|
||
class JobPackagesSQLRepository(JobPackagesRepository): | ||
def __init__(self, engine: Engine, table: Table): | ||
self.engine = engine | ||
self.table = table | ||
|
||
def get_all(self): | ||
with self.engine.connect() as conn: | ||
statement = self.table.select() | ||
result = conn.execute(statement).all() | ||
return [ | ||
JobPackageModel( | ||
exp_id=row.exp_id, | ||
package_name=row.package_name, | ||
job_name=row.job_name, | ||
) | ||
for row in result | ||
] | ||
|
||
|
||
def create_job_packages_repository(expid: str, wrapper=False) -> JobPackagesRepository: | ||
""" | ||
Create a job packages repository. | ||
:param wrapper: Whether to use the alternative wrapper job packages table. | ||
""" | ||
engine = create_sqlite_db_engine(ExperimentPaths(expid).job_packages_db) | ||
table = tables.wrapper_job_package_table if wrapper else tables.job_package_table | ||
return JobPackagesSQLRepository(engine, table) |