Skip to content

Commit

Permalink
Add strict set of events to monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
cuom1999 authored and Xyene committed Apr 21, 2023
1 parent 582f444 commit 17b0bcf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion dmoj/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

try:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from watchdog.events import (
FileSystemEventHandler,
EVENT_TYPE_MOVED,
EVENT_TYPE_DELETED,
EVENT_TYPE_MODIFIED,
EVENT_TYPE_CREATED,
)

has_watchdog_installed = True
except ImportError:
Expand Down Expand Up @@ -52,11 +58,20 @@ def run(self):


class SendProblemsHandler(FileSystemEventHandler):
ALLOWED_EVENT_TYPES = (
EVENT_TYPE_MOVED,
EVENT_TYPE_DELETED,
EVENT_TYPE_MODIFIED,
EVENT_TYPE_CREATED,
)

def __init__(self, refresher=None):
self.refresher = refresher
self.callback = None

def on_any_event(self, event):
if event.event_type not in self.ALLOWED_EVENT_TYPES:
return
if self.callback is not None:
self.callback()
if self.refresher is not None:
Expand Down

0 comments on commit 17b0bcf

Please sign in to comment.