file_manager: refactor metadata processing
When destructively iterating over pending metdata requests don't pop the pending item until metadata processing is complete. If a call to `parse_metadata()` has a request pending, return the asyncio Event associated with that request. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
88137d5898
commit
b7c64443db
|
@ -1492,11 +1492,14 @@ class MetadataStorage:
|
||||||
fname: str,
|
fname: str,
|
||||||
path_info: Dict[str, Any]
|
path_info: Dict[str, Any]
|
||||||
) -> asyncio.Event:
|
) -> asyncio.Event:
|
||||||
|
if fname in self.pending_requests:
|
||||||
|
return self.pending_requests[fname][1]
|
||||||
mevt = asyncio.Event()
|
mevt = asyncio.Event()
|
||||||
ext = os.path.splitext(fname)[1]
|
ext = os.path.splitext(fname)[1]
|
||||||
if fname in self.pending_requests or \
|
if (
|
||||||
ext not in VALID_GCODE_EXTS or \
|
ext not in VALID_GCODE_EXTS or
|
||||||
self._has_valid_data(fname, path_info):
|
self._has_valid_data(fname, path_info)
|
||||||
|
):
|
||||||
# request already pending or not necessary
|
# request already pending or not necessary
|
||||||
mevt.set()
|
mevt.set()
|
||||||
return mevt
|
return mevt
|
||||||
|
@ -1511,7 +1514,7 @@ class MetadataStorage:
|
||||||
async def _process_metadata_update(self) -> None:
|
async def _process_metadata_update(self) -> None:
|
||||||
while self.pending_requests:
|
while self.pending_requests:
|
||||||
fname, (path_info, mevt) = \
|
fname, (path_info, mevt) = \
|
||||||
self.pending_requests.popitem()
|
list(self.pending_requests.items())[0]
|
||||||
if self._has_valid_data(fname, path_info):
|
if self._has_valid_data(fname, path_info):
|
||||||
mevt.set()
|
mevt.set()
|
||||||
continue
|
continue
|
||||||
|
@ -1535,6 +1538,7 @@ class MetadataStorage:
|
||||||
}
|
}
|
||||||
logging.info(
|
logging.info(
|
||||||
f"Unable to extract medatadata from file: {fname}")
|
f"Unable to extract medatadata from file: {fname}")
|
||||||
|
self.pending_requests.pop(fname, None)
|
||||||
mevt.set()
|
mevt.set()
|
||||||
self.busy = False
|
self.busy = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue