Skip to content

Commit

Permalink
Active lock between reader and storer
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelo7 committed Apr 4, 2024
1 parent 9474e98 commit 1ebefcd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 0 additions & 1 deletion oc_ocdm/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.support.reporter import Reporter
from oc_ocdm.support.support import build_graph_from_results

if TYPE_CHECKING:
from typing import Any, Dict, List, Optional, Set
from oc_ocdm.graph.graph_set import GraphSet
Expand Down
17 changes: 10 additions & 7 deletions oc_ocdm/storer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from oc_ocdm.support.query_utils import get_update_query
from oc_ocdm.support.reporter import Reporter
from oc_ocdm.support.support import find_paths
from filelock import FileLock

if TYPE_CHECKING:
from typing import Any, Dict, List, Optional, Set, Tuple
Expand Down Expand Up @@ -169,13 +170,15 @@ def store_all(self, base_dir: str, base_iri: str, context_path: str = None, proc
stored_g = None
# Here we try to obtain a reference to the currently stored graph
output_filepath = relevant_path.replace(os.path.splitext(relevant_path)[1], ".zip") if self.zip_output else relevant_path
if os.path.exists(output_filepath):
stored_g = Reader(context_map=self.context_map).load(output_filepath)
if stored_g is None:
stored_g = ConjunctiveGraph()
for entity_in_path in entities_in_path:
self.store(entity_in_path, stored_g, relevant_path, context_path, False)
self._store_in_file(stored_g, relevant_path, context_path)
lock = FileLock(f"{output_filepath}.lock")
with lock:
if os.path.exists(output_filepath):
stored_g = Reader(context_map=self.context_map).load(output_filepath)
if stored_g is None:
stored_g = ConjunctiveGraph()
for entity_in_path in entities_in_path:
self.store(entity_in_path, stored_g, relevant_path, context_path, False)
self._store_in_file(stored_g, relevant_path, context_path)

return list(relevant_paths.keys())

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "oc_ocdm"
version = "8.0.1"
version = "8.0.2"
description = "Object mapping library for manipulating RDF graphs that are compliant with the OpenCitations datamodel."
authors = [
"Silvio Peroni <essepuntato@gmail.com>",
Expand Down

0 comments on commit 1ebefcd

Please sign in to comment.