Kyoo/scanner/scanner/monitor.py
2023-08-02 00:57:27 +09:00

23 lines
615 B
Python

import logging
from watchfiles import awatch, Change
from .utils import ProviderError
from .scanner import Scanner
async def monitor(path: str, scanner: Scanner):
async for changes in awatch(path):
for (event, file) in changes:
try:
if event == Change.added:
await scanner.identify(file)
elif event == Change.deleted:
await scanner.delete(file)
elif event == Change.modified:
pass
else:
print(f"Change {event} occured for file {file}")
except ProviderError as e:
logging.error(str(e))
except Exception as e:
logging.exception("Unhandled error", exc_info=e)