Skip to content

Commit

Permalink
feat: add comment metadata api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
makkus committed Mar 22, 2024
1 parent cbf625f commit b61e7f8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/kiara/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import typing
import uuid
from enum import Enum
from pathlib import Path

from appdirs import AppDirs

Expand Down Expand Up @@ -139,6 +140,9 @@
VALUE_ATTR_DELIMITER = "::"
VALID_VALUE_QUERY_CATEGORIES = ["data", "properties"]

CHUNK_CACHE_BASE_DIR = Path(kiara_app_dirs.user_cache_dir) / "data" / "chunks"
CHUNK_CACHE_DIR_DEPTH = 2
CHUNK_CACHE_DIR_WIDTH = 1

class SpecialValue(Enum):

Expand Down
23 changes: 23 additions & 0 deletions src/kiara/interfaces/python_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3117,6 +3117,29 @@ def get_job_record(self, job_id: Union[str, uuid.UUID]) -> Union["JobRecord", No
job_record = self.context.job_registry.get_job_record(job_id=job_id)
return job_record

def set_job_comment(self, job_id: Union[str, uuid.UUID], comment: str, force: bool = True):
"""Set a comment for the specified job.
Arguments:
job_id: the job id
comment: the comment to set
force: whether to overwrite an existing comment
"""

from kiara.models.metadata import CommentMetadata

if isinstance(job_id, str):
job_id = uuid.UUID(job_id)

metadata = CommentMetadata(comment=comment)
items = {
"comment": comment
}

self.context.metadata_registry.register_job_metadata_items(
job_id=job_id, items=items, force=force
)

def get_job_comment(self, job_id: Union[str, uuid.UUID]) -> Union[str, None]:
"""Retrieve the comment for the specified job.
Expand Down
9 changes: 5 additions & 4 deletions src/kiara/registries/data/data_store/sqlite_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sqlalchemy import text
from sqlalchemy.engine import Connection, Engine

from kiara.defaults import CHUNK_COMPRESSION_TYPE, kiara_app_dirs
from kiara.defaults import CHUNK_COMPRESSION_TYPE, kiara_app_dirs, CHUNK_CACHE_BASE_DIR, CHUNK_CACHE_DIR_DEPTH, CHUNK_CACHE_DIR_WIDTH
from kiara.models.values.value import PersistedData, Value
from kiara.registries import (
ARCHIVE_CONFIG_CLS,
Expand Down Expand Up @@ -94,10 +94,11 @@ def __init__(
)
self._db_path: Union[Path, None] = None
self._cached_engine: Union[Engine, None] = None
self._data_cache_dir = Path(kiara_app_dirs.user_cache_dir) / "data" / "chunks"
self._data_cache_dir = CHUNK_CACHE_BASE_DIR
self._data_cache_dir.mkdir(parents=True, exist_ok=True, mode=0o700)
self._cache_dir_depth = 2
self._cache_dir_width = 1

self._cache_dir_depth = CHUNK_CACHE_DIR_DEPTH
self._cache_dir_width = CHUNK_CACHE_DIR_WIDTH
self._value_id_cache: Union[Iterable[uuid.UUID], None] = None
self._use_wal_mode: bool = archive_config.use_wal_mode
# self._lock: bool = True
Expand Down
2 changes: 2 additions & 0 deletions src/kiara/registries/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def register_job_metadata_items(
job_id: uuid.UUID,
items: Mapping[str, Any],
store: Union[str, uuid.UUID, None] = None,
force: bool = False,
) -> None:

for key, value in items.items():
Expand All @@ -205,6 +206,7 @@ def register_job_metadata_items(
reference_item_type="job",
reference_item_id=str(job_id),
store=store,
force=force,
)

def retrieve_job_metadata_items(self, job_id: uuid.UUID):
Expand Down

0 comments on commit b61e7f8

Please sign in to comment.