Skip to content

Commit

Permalink
added reset cleanup functionality (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
apmariglis authored Apr 7, 2022
1 parent c95f8c0 commit d624cd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mipengine/controller/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def _get_node_info_by_id(self, node_id: str) -> _NodeInfoDTO:

raise KeyError(f"Node with id '{node_id}' is not currently available.")

# This is only supposed to be called from a test.
# In all other circumstances cleanup should not be reset manually
def _reset_cleanup(self):
self._cleanup_file_processor._delete_cleanup_file()


def _create_node_task_handler(node_info: _NodeInfoDTO) -> NodeTasksHandlerCelery:
return NodeTasksHandlerCelery(
Expand Down Expand Up @@ -233,3 +238,9 @@ def _write_to_cleanup_file(self, toml_string: str):
# renaming is atomic. Of course if more Controllers are spawn the file is very
# likely to become corrupted
os.rename(self._cleanup_file_tmp_path, self._cleanup_file_path)

def _delete_cleanup_file(self):
cleanup_file_path = Path(
controller_config.cleanup.contextids_cleanup_folder
).joinpath(Path(CONTEXT_ID_CLEANUP_FILE))
cleanup_file_path.unlink()
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ async def test_cleanup_after_uninterrupted_algorithm_execution(
await asyncio.sleep(2)

# Start the cleanup loop
controller._cleaner._reset_cleanup()
controller.start_cleanup_loop()
request_id = get_a_uniqueid()
context_id = get_a_uniqueid()
Expand Down Expand Up @@ -383,6 +384,7 @@ async def test_cleanup_after_uninterrupted_algorithm_execution_without_releasing
await asyncio.sleep(2)

# Start the cleanup loop
controller._cleaner._reset_cleanup()
controller.start_cleanup_loop()

request_id = get_a_uniqueid()
Expand Down Expand Up @@ -528,6 +530,7 @@ async def test_cleanup_rabbitmq_down_algorithm_execution(
await asyncio.sleep(2)

# Start the cleanup loop
controller._cleaner._reset_cleanup()
controller.start_cleanup_loop()

request_id = get_a_uniqueid()
Expand Down Expand Up @@ -699,6 +702,7 @@ async def test_cleanup_node_service_down_algorithm_execution(
await asyncio.sleep(2)

# Start the cleanup loop
controller._cleaner._reset_cleanup()
controller.start_cleanup_loop()

request_id = get_a_uniqueid()
Expand Down Expand Up @@ -862,6 +866,7 @@ async def test_cleanup_controller_restart(
await asyncio.sleep(2)

# Start the cleanup loop
controller._cleaner._reset_cleanup()
controller.start_cleanup_loop()

request_id = get_a_uniqueid()
Expand Down

0 comments on commit d624cd7

Please sign in to comment.