Skip to content

Commit

Permalink
Don't force json data stores to be on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirddog committed Dec 19, 2023
1 parent af8827c commit c1ea12c
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ def _data_store_exists_at_location(location: str, identifier: str) -> bool:
return FileSystemService.file_exists_at_relative_path(location, _data_store_filename(identifier))


def _data_store_location_for_task(spiff_task: SpiffTask, identifier: str) -> str | None:
def _data_store_location_for_task(spiff_task: SpiffTask, identifier: str, check_disk: bool) -> str | None:
location = _process_model_location_for_task(spiff_task)
if location is None:
return None
if _data_store_exists_at_location(location, identifier):
return location
location = ReferenceCacheService.upsearch(location, identifier, "data_store")
# if location is None or not _data_store_exists_at_location(location, identifier):
# return None
if location is None
return None
if check_disk and not _data_store_exists_at_location(location, identifier):
return None
return location


Expand Down Expand Up @@ -76,7 +78,7 @@ def build_response_item(model: Any) -> dict[str, Any]:
def get(self, my_task: SpiffTask) -> None:
"""get."""
model: JSONDataStoreModel | None = None
location = _data_store_location_for_task(my_task, self.bpmn_id)
location = _data_store_location_for_task(my_task, self.bpmn_id, False)
if location is not None:
model = db.session.query(JSONDataStoreModel).filter_by(identifier=self.bpmn_id, location=location).first()
if model is None:
Expand All @@ -85,10 +87,13 @@ def get(self, my_task: SpiffTask) -> None:

def set(self, my_task: SpiffTask) -> None:
"""set."""
location = _data_store_location_for_task(my_task, self.bpmn_id)
location = _data_store_location_for_task(my_task, self.bpmn_id, False)
if location is None:
raise Exception(f"Unable to write to data store '{self.bpmn_id}' using location '{location}'.")
data = my_task.data[self.bpmn_id]

# TODO: validate data against schema

model = JSONDataStoreModel(
identifier=self.bpmn_id,
location=location,
Expand Down Expand Up @@ -127,15 +132,15 @@ class JSONFileDataStore(BpmnDataStoreSpecification): # type: ignore

def get(self, my_task: SpiffTask) -> None:
"""get."""
location = _data_store_location_for_task(my_task, self.bpmn_id)
location = _data_store_location_for_task(my_task, self.bpmn_id, True)
if location is None:
raise Exception(f"Unable to read from data store '{self.bpmn_id}' using location '{location}'.")
contents = FileSystemService.contents_of_json_file_at_relative_path(location, _data_store_filename(self.bpmn_id))
my_task.data[self.bpmn_id] = contents

def set(self, my_task: SpiffTask) -> None:
"""set."""
location = _data_store_location_for_task(my_task, self.bpmn_id)
location = _data_store_location_for_task(my_task, self.bpmn_id, True)
if location is None:
raise Exception(f"Unable to write to data store '{self.bpmn_id}' using location '{location}'.")
data = my_task.data[self.bpmn_id]
Expand Down

0 comments on commit c1ea12c

Please sign in to comment.