Skip to content

Commit

Permalink
Engine: Change signature of set_process_state_change_timestamp
Browse files Browse the repository at this point in the history
The function took a `Process` instance but then only uses it to fetch
its associated node. Since a `Process` instance is way more difficult to
mock, it makes testing the function unnecessarily complicated. Since it
only needs the process node, the signature is changed to accept the node
instead of the process. This utility function is unlikely to be used in
client code, justifying this technically backwards incompatible change.
  • Loading branch information
sphuber committed Jul 24, 2024
1 parent 71422eb commit 5611dda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/aiida/engine/processes/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def on_entered(self, from_state: Optional[plumpy.process_states.State]) -> None:
self.node.set_process_state(self._state.LABEL) # type: ignore[arg-type]

self._save_checkpoint()
set_process_state_change_timestamp(self)
set_process_state_change_timestamp(self.node)
super().on_entered(from_state)

@override
Expand Down
12 changes: 7 additions & 5 deletions src/aiida/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Iterator, List, Optional, Tuple, Type, Union

if TYPE_CHECKING:
from aiida.orm import ProcessNode

from .processes import Process, ProcessBuilder
from .runners import Runner

Expand Down Expand Up @@ -259,7 +261,7 @@ def loop_scope(loop) -> Iterator[None]:
asyncio.set_event_loop(current)


def set_process_state_change_timestamp(process: 'Process') -> None:
def set_process_state_change_timestamp(node: 'ProcessNode') -> None:
"""Set the global setting that reflects the last time a process changed state, for the process type
of the given process, to the current timestamp. The process type will be determined based on
the class of the calculation node it has as its database container.
Expand All @@ -270,15 +272,15 @@ def set_process_state_change_timestamp(process: 'Process') -> None:
from aiida.manage import get_manager
from aiida.orm import CalculationNode, ProcessNode, WorkflowNode

if isinstance(process.node, CalculationNode):
if isinstance(node, CalculationNode):
process_type = 'calculation'
elif isinstance(process.node, WorkflowNode):
elif isinstance(node, WorkflowNode):
process_type = 'work'
elif isinstance(process.node, ProcessNode):
elif isinstance(node, ProcessNode):
# This will only occur for testing, as in general users cannot launch plain Process classes
return
else:
raise ValueError(f'unsupported calculation node type {type(process.node)}')
raise ValueError(f'unsupported calculation node type {type(node)}')

key = PROCESS_STATE_CHANGE_KEY.format(process_type)
description = PROCESS_STATE_CHANGE_DESCRIPTION.format(process_type)
Expand Down

0 comments on commit 5611dda

Please sign in to comment.