Skip to content

Commit

Permalink
refactor: simplify library watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ex4 committed Dec 17, 2024
1 parent 8b5a6ea commit ecaf409
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def init():
global watcher_thread
# Create and start the file watcher
logger.info('Initializing File Watcher...')
watcher = Watcher([], on_library_change)
watcher = Watcher(on_library_change)
watcher_thread = threading.Thread(target=watcher.run)
watcher_thread.daemon = True
watcher_thread.start()
Expand Down
7 changes: 2 additions & 5 deletions app/file_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ def call_it():
return decorator

class Watcher:
def __init__(self, directories, callback):
self.directories = set(directories) # Use a set to store directories
def __init__(self, callback):
self.directories = set() # Use a set to store directories
self.callback = callback
self.event_handler = Handler(self.callback)
self.observer = PollingObserver()
self.scheduler_map = {}

def run(self):
for directory in self.directories:
task = self.observer.schedule(self.event_handler, directory, recursive=True)
self.scheduler_map[directory] = task
self.observer.start()
logger.debug('Successfully started observer.')

Expand Down

0 comments on commit ecaf409

Please sign in to comment.