mercure-imaging / mercure

mercure DICOM Orchestrator
https://mercure-imaging.org
MIT License
65 stars 31 forks source link

is_ready_for_processing exception with more than 1 processor #44

Closed alipairon closed 1 year ago

alipairon commented 1 year ago

Describe the bug In case you are using more than 1 processor (6 in my case) there are situations when function is_ready_for_processing throws an exception when folder to process does not exist which causes a full stop of processor until it restarted.

The exception like this: Exception in thread Thread-139331: Traceback (most recent call last): File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/usr/lib/python3.8/threading.py", line 1254, in run self.function(*self.args, **self.kwargs) File "/opt/mercure/app/common/helper.py", line 70, in _run self.function(*self.args, **self.kwargs) File "/opt/mercure/app/processor.py", line 192, in run_processor while search_folder(call_counter): File "/opt/mercure/app/processor.py", line 62, in search_folder if is_ready_for_processing(entry.path): File "/opt/mercure/app/process/status.py", line 20, in is_ready_for_processing and len(list(path.glob("*.dcm"))) > 0 File "/usr/lib/python3.8/pathlib.py", line 1140, in glob for p in selector.select_from(self): File "/usr/lib/python3.8/pathlib.py", line 534, in _select_from with scandir(parent_path) as scandir_it: FileNotFoundError: [Errno 2] No such file or directory: '/opt/mercure/data/processing/2d4d7394-7c21-11ed-a6f8-0242ac120005'

To Reproduce This would be hard to reproduce, except on a really heavy load with a lot of processors.

Expected behavior Continue to work.

Additional context I suppose there are must be an try -> except behaviour in is_ready_for_processing def.

Something like:

def is_ready_for_processing(folder) -> bool:
    """Checks if a case in the processing folder is ready for the processor."""
    try:
        path = Path(folder)
        folder_status = (
            not (path / mercure_names.LOCK).exists()
            and not (path / mercure_names.PROCESSING).exists()
            and len(list(path.glob("*.dcm"))) > 0
        )
        return folder_status
    except:
        return False

But I haven't tested it.

tblock79 commented 1 year ago

Addressed with commit 75e6543916010adf682db338e6e595d05167bd8e

If you need to run many processor jobs in parallel, you might want to take a look at a Nomad-type installation (which would also allow you to run processes on different compute nodes). This would scale and manage resources in a better way.