chore: remove watchdog

This commit is contained in:
Sam Chau
2024-09-08 02:31:59 +09:30
parent 30bc238105
commit 28851e0270
3 changed files with 2 additions and 52 deletions

View File

@@ -3,4 +3,4 @@ WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "run_dev.py"]
CMD ["python", "run.py"]

View File

@@ -3,5 +3,4 @@ Flask-CORS==3.0.10
PyYAML==5.4.1
requests==2.26.0
Werkzeug==2.0.1
GitPython==3.1.24
watchdog
GitPython==3.1.24

View File

@@ -1,49 +0,0 @@
import sys
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import subprocess
import os
class Reloader(FileSystemEventHandler):
def __init__(self):
self.process = None
self.last_restart = 0
self.start_app()
def on_any_event(self, event):
if event.src_path.endswith(
'.py') and not event.src_path.endswith('run_dev.py'):
current_time = time.time()
if current_time - self.last_restart > 1: # Prevent rapid restarts
print(f"Detected change in {event.src_path}, restarting...")
self.restart_app()
self.last_restart = current_time
def start_app(self):
env = os.environ.copy()
env['FLASK_ENV'] = 'development'
self.process = subprocess.Popen([sys.executable, 'run.py'], env=env)
def restart_app(self):
if self.process:
self.process.terminate()
self.process.wait()
self.start_app()
if __name__ == "__main__":
path = '.'
event_handler = Reloader()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()