mercure-imaging / mercure

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

Multiple dispatchers bug #46

Closed alipairon closed 1 year ago

alipairon commented 1 year ago

Hello!

In case you have a multiple dispatchers (docker in my case) they are conflicting with each over directories to dispatch sometimes.

For example:

Exception in thread Thread-3115173:
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/dispatcher.py", line 74, in dispatch
items = sorted(Path(config.mercure.outgoing_folder).iterdir(), key=os.path.getmtime)
File "/usr/lib/python3.8/genericpath.py", line 55, in getmtime
return os.stat(filename).st_mtime
FileNotFoundError: [Errno 2] No such file or directory: '/opt/mercure/data/outgoing/2bc7a132-97ad-11ed-9010-0242ac120012'

I suggest adding a try/except behaviour in def dispatch of dispatcher.py at this part of the code.

try:
        items = sorted(Path(config.mercure.outgoing_folder).iterdir(), key=os.path.getmtime)
        for entry in items:
            # First, check if dispatching might have been suspended via the UI
            if dispatcher_lockfile and dispatcher_lockfile.exists():
                if not dispatcher_is_locked:
                    dispatcher_is_locked = True
                    logger.info(f"Dispatching halted")
                break
            else:
                if dispatcher_is_locked:
                    dispatcher_is_locked = False
                    logger.info("Dispatching resumed")

            # Now process the folders that are ready for dispatching
            if entry.is_dir() and is_ready_for_sending(entry):
                execute(Path(entry), success_folder, error_folder, retry_max, retry_delay)

            # If termination is requested, stop processing series after the
            # active one has been completed
            if helper.is_terminated():
                break
    except:
        return
tblock79 commented 1 year ago

Thanks for finding and reporting this issue!

Has been addressed with commit 2096565eded589adf26dded887c49e70a51001a6.