Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
fix #366 update last_edit_date when job fails or is abandoned (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinAV authored Nov 30, 2022
1 parent 6d9ea86 commit 7cdbabf
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/taipy/core/data/abstract_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(
)
self._engine = None
if not self._last_edit_date:
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

def _check_required_properties(self, properties: Dict):
db_engine = properties.get(self.__DB_ENGINE_KEY)
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(
**properties,
)
if not self._last_edit_date and isfile(self._path):
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

@classmethod
def storage_type(cls) -> str:
Expand Down
19 changes: 8 additions & 11 deletions src/taipy/core/data/data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ def write(self, data, job_id: Optional[JobId] = None):
from ._data_manager_factory import _DataManagerFactory

self._write(data)
self.unlock_edit(job_id=job_id)
self.last_edit_date = datetime.now() # type: ignore
if job_id:
self._job_ids.append(job_id)
self.unlock_edit()
_DataManagerFactory._build_manager()._set(self)

def lock_edit(self):
Expand All @@ -338,26 +341,20 @@ def lock_edition(self):
def unlock_edit(self, at: datetime = None, job_id: JobId = None):
"""Unlocks the edit of the data node.
The _last_edit_date_ is updated.
Parameters:
at (datetime): The optional datetime of the last modification.
If no _at_ datetime is provided, the current datetime is used.
job_id (JobId^): An optional identifier of the writer.
at (datetime): Deprecated.
job_id (JobId^): Deprecated.
Note:
The data node can be locked with the method `(DataNode.)lock_edit()^`.
"""
self.last_edit_date = at or datetime.now() # type: ignore
self.edit_in_progress = False # type: ignore
if job_id:
self._job_ids.append(job_id)

def unlock_edition(self, at: datetime = None, job_id: JobId = None):
"""
Deprecated. Use unlock_edit instead.
Deprecated. Use (DataNode.)unlock_edit()^` instead.
"""
_warn_deprecated("unlock_edition", suggest="unlock_edit")
self.unlock_edit(at, job_id)
self.unlock_edit()

def filter(self, operators: Union[List, Tuple], join_operator=JoinOperator.AND):
"""Read the data referenced by the data node, appying a filter.
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(
)

if not self._last_edit_date and isfile(self._path):
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

@property # type: ignore
@_self_reload(DataNode._MANAGER_NAME)
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(
**properties,
)
if not self._last_edit_date:
self.unlock_edit()
self.last_edit_date = datetime.now()

@classmethod
def storage_type(cls) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
self._encoder = self._properties.get(self._ENCODER_KEY, _DefaultJSONEncoder)

if not self._last_edit_date and isfile(self._path): # type: ignore
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

@classmethod
def storage_type(cls) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
self._encoder = custom_encoder

if not self._last_edit_date:
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

def _check_custom_document(self, custom_document):
if not isclass(custom_document):
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(
if self._path is None:
self._path = self.__build_path()
if not self._last_edit_date and os.path.exists(self._path):
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore
if default_value is not None and not os.path.exists(self._path):
self.write(default_value)

Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,4 @@ def __hash__(self):

def _unlock_edit_on_outputs(self):
for dn in self.task.output.values():
dn.unlock_edit(at=dn.last_edit_date)
dn.unlock_edit()
6 changes: 3 additions & 3 deletions tests/core/data/test_csv_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_read_without_header(self):

# Create CSVDataNode with modin exposed_type
csv_data_node_as_modin = CSVDataNode(
"bar", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": "modin"}
"baz", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": "modin"}
)
data_modin = csv_data_node_as_modin.read()
assert isinstance(data_modin, modin_pd.DataFrame)
Expand All @@ -153,7 +153,7 @@ def test_read_without_header(self):

# Create CSVDataNode with numpy exposed_type
csv_data_node_as_numpy = CSVDataNode(
"bar", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": "numpy"}
"qux", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": "numpy"}
)
data_numpy = csv_data_node_as_numpy.read()
assert isinstance(data_numpy, np.ndarray)
Expand All @@ -162,7 +162,7 @@ def test_read_without_header(self):

# Create the same CSVDataNode but with custom exposed_type
csv_data_node_as_custom_object = CSVDataNode(
"bar", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": MyCustomObject}
"quux", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": MyCustomObject}
)
data_custom = csv_data_node_as_custom_object.read()
assert isinstance(data_custom, list)
Expand Down
28 changes: 14 additions & 14 deletions tests/core/data/test_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,27 @@ def test_read_write(self):

def test_ready_for_reading(self):
dn = InMemoryDataNode("foo_bar", Scope.CYCLE)
assert dn.last_edition_date is None
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == []

dn.lock_edition()
assert dn.last_edition_date is None
dn.lock_edit()
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == []

dn.unlock_edition(a_date := datetime.now(), job_id := JobId("a_job_id"))
assert dn.last_edition_date == a_date
assert dn.is_ready_for_reading
assert dn.job_ids == [job_id]
dn.unlock_edit(datetime.now(), JobId("a_job_id"))
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == []

dn.lock_edition()
assert dn.last_edition_date == a_date
dn.lock_edit()
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == [job_id]
assert dn.job_ids == []

dn.unlock_edition(b_date := datetime.now())
assert dn.last_edition_date == b_date
dn.write("toto", job_id := JobId("a_job_id"))
assert dn.last_edit_date is not None
assert dn.is_ready_for_reading
assert dn.job_ids == [job_id]

Expand Down Expand Up @@ -587,8 +587,8 @@ def test_unlock_edition_deprecated(self):

with pytest.warns(DeprecationWarning):
with mock.patch("src.taipy.core.data.data_node.DataNode.unlock_edit") as unlock_edit:
dn.unlock_edition(d := datetime.now(), None)
unlock_edit.assert_called_once_with(d, None)
dn.unlock_edition(datetime.now(), None)
unlock_edit.assert_called_once_with()

def test_lock_edition_deprecated(self):
dn = FakeDataNode("foo")
Expand Down

0 comments on commit 7cdbabf

Please sign in to comment.