Skip to content

Commit

Permalink
Count dsmc processes (#2690)
Browse files Browse the repository at this point in the history
### Changed

- Allow 3 running dsmc processes
  • Loading branch information
henrikstranneheim authored Nov 15, 2023
1 parent db24a1a commit f98e79c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions cg/meta/backup/pdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

SERVER = "hasta"
NO_FILE_FOUND_ANSWER = "ANS1092W"
MAX_NR_OF_DSMC_PROCESSES: int = 3


class PdcAPI:
Expand All @@ -39,14 +40,17 @@ def validate_is_dsmc_running(cls) -> bool:
Exception: for all non-exit exceptions.
"""
is_dsmc_running: bool = False
dsmc_process_count: int = 0
try:
for process in psutil.process_iter():
if "dsmc" in process.name():
is_dsmc_running = True
LOG.debug(process.name())
if "dsmc" == process.name():
dsmc_process_count += 1
except Exception as error:
LOG.debug(f"{error}")
if is_dsmc_running:
LOG.debug("A Dsmc process is already running")
if dsmc_process_count >= MAX_NR_OF_DSMC_PROCESSES:
is_dsmc_running = True
LOG.debug("Too many Dsmc processes are already running")
return is_dsmc_running

def archive_file_to_pdc(self, file_path: str) -> None:
Expand Down Expand Up @@ -93,7 +97,7 @@ def validate_is_flow_cell_backup_possible(
FlowCellEncryptionError if encryption is not complete.
"""
if self.validate_is_dsmc_running():
raise DsmcAlreadyRunningError("A Dsmc process is already running")
raise DsmcAlreadyRunningError("Too many Dsmc processes are already running")
if db_flow_cell and db_flow_cell.has_backup:
raise FlowCellAlreadyBackedUpError(
f"Flow cell: {db_flow_cell.name} is already backed-up"
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/backup/test_backup_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def test_backup_flow_cells_when_dsmc_is_running(
# THEN exits without any errors
assert result.exit_code == EXIT_SUCCESS

# THEN communicate Dsmc process is already running
assert "A Dsmc process is already running" in caplog.text
# THEN communicate too many Dsmc processes are already running
assert "Too many Dsmc processes are already running" in caplog.text


def test_backup_flow_cells_when_flow_cell_already_has_backup(
Expand Down

0 comments on commit f98e79c

Please sign in to comment.