Open nasdas-dev opened 5 years ago
There is a --no-inotify
argument that fall back on a time loop.
I have no idea if there is an easy way to interface python with fswatch. If there is it might be a good thing to explore.
Also, inotify
is automatically disabled on non-Linux systems.
fswatch
(or watchdog
for Python) aren't directly usable in Paperless.
For detecting new docs to consume, we want to react to the event that a file has been closed after being written to.
This can't be expressed by the more general event types (created
, modified
) of common cross-platform fs monitoring libs.
Well, a very "stupid" consumer script would be to create a small python script that simply scans the /consume directory, keeps a list, and compares it. If the entries are different - read the directory again (or the list delta). We could provide this as a fall-back option (for example configurable as environment variable for docker-compose.env).
Let me know if you need a quick write up for that.
As a real quick POC:
import os
import time
dirToWatch = "./watch/"
fileList = []
timeToSleep = 5
while True:
newFileList = os.listdir(dirToWatch)
if fileList != newFileList:
print(f"changes detected in {dirToWatch}:")
changes = set(newFileList) - set(fileList)
print(changes)
fileList = newFileList
else:
print("no new changes")
time.sleep(timeToSleep)
➜ others python3 watchdog.py
changes detected in ./watch/:
{'me', 'menot'}
no new changes
no new changes
changes detected in ./watch/:
{'file', 'new'}
no new changes
a very "stupid" consumer script would be to ...
How is this different from the existing, fall-back consumer script?
Oh, I wasn't aware there was an consumer script already, my bad. Please ignore what I said then.
inotify is incompatible with macOS and I'd suggest a mac build with fswatch instead.