Fix some compose panel bugs and reload workers when changed
This commit is contained in:
@@ -23,5 +23,7 @@ log-level=debug
|
||||
|
||||
# Autoreload on code changes (graceful reload)
|
||||
py-autoreload=1
|
||||
py-autoreload-on-edit=/code/GIA/core
|
||||
py-autoreload-on-edit=/code/GIA/app
|
||||
# In the container the repository is mounted at /code, not /code/GIA
|
||||
# point autoreload at the actual in-container paths
|
||||
py-autoreload-on-edit=/code/core
|
||||
py-autoreload-on-edit=/code/app
|
||||
@@ -1,6 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Watch for code changes in core/ and app/ and restart ur_gia container.
|
||||
Watch for code changes and restart a target container.
|
||||
|
||||
This script watches one or more directories (set via the `WATCH_PATHS`
|
||||
environment variable, comma-separated) and restarts the container named by
|
||||
`TARGET_CONTAINER` (defaults to `ur_gia`) when a filesystem change is detected.
|
||||
|
||||
Typical usage in this repo (examples are provided in `docker-compose.yml`):
|
||||
|
||||
- To restart the runtime router (UR) when core code changes set:
|
||||
WATCH_PATHS=/code/core
|
||||
TARGET_CONTAINER=ur_gia
|
||||
|
||||
- To restart the scheduling command when app code changes set:
|
||||
WATCH_PATHS=/code/app
|
||||
TARGET_CONTAINER=scheduling_gia
|
||||
|
||||
If you need to force a restart manually (for example to refresh a running
|
||||
management command), you can "touch" any file under the watched path:
|
||||
|
||||
docker compose exec <service> sh -c 'touch /code/core/__restart__'
|
||||
|
||||
The watcher ignores `__pycache__`, `.pyc` files and `.git` paths.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
@@ -40,17 +61,16 @@ class ChangeHandler(FileSystemEventHandler):
|
||||
self._restart_ur()
|
||||
|
||||
def _restart_ur(self):
|
||||
print(f'[{time.strftime("%H:%M:%S")}] Restarting ur_gia...', flush=True)
|
||||
# Determine target container from environment (default `ur_gia`)
|
||||
target = os.environ.get('TARGET_CONTAINER', 'ur_gia')
|
||||
print(f'[{time.strftime("%H:%M:%S")}] Restarting {target}...', flush=True)
|
||||
# Try podman first (preferred in this setup), then docker
|
||||
result = subprocess.run(
|
||||
'podman restart ur_gia 2>/dev/null || docker restart ur_gia 2>/dev/null',
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
)
|
||||
cmd = f"podman restart {target} 2>/dev/null || docker restart {target} 2>/dev/null"
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True)
|
||||
if result.returncode == 0:
|
||||
print(f'[{time.strftime("%H:%M:%S")}] ur_gia restarted successfully', flush=True)
|
||||
print(f'[{time.strftime("%H:%M:%S")}] {target} restarted successfully', flush=True)
|
||||
else:
|
||||
print(f'[{time.strftime("%H:%M:%S")}] ur_gia restart failed', flush=True)
|
||||
print(f'[{time.strftime("%H:%M:%S")}] {target} restart failed', flush=True)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
@@ -58,12 +78,16 @@ def main():
|
||||
handler = ChangeHandler()
|
||||
observer = Observer()
|
||||
|
||||
# Watch both core and app directories
|
||||
watch_paths = ['/code/GIA/core', '/code/GIA/app']
|
||||
# Allow overriding watched paths via environment variable `WATCH_PATHS`.
|
||||
# Default is `/code/core,/code/app` but you can set e.g. `WATCH_PATHS=/code/core`
|
||||
watch_paths_env = os.environ.get('WATCH_PATHS', '/code/core,/code/app')
|
||||
watch_paths = [p.strip() for p in watch_paths_env.split(',') if p.strip()]
|
||||
for path in watch_paths:
|
||||
if os.path.exists(path):
|
||||
observer.schedule(handler, path, recursive=True)
|
||||
print(f'Watching: {path}', flush=True)
|
||||
else:
|
||||
print(f'Not found (will not watch): {path}', flush=True)
|
||||
|
||||
observer.start()
|
||||
print(f'[{time.strftime("%H:%M:%S")}] File watcher started. Monitoring for changes...', flush=True)
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Simple file watcher using stat() instead of watchdog (no external deps).
|
||||
Watches core/ and app/ for changes and restarts ur_gia.
|
||||
|
||||
This lightweight watcher can be used when you don't want the `watchdog`
|
||||
dependency. Configure the directories to watch using the `WATCH_PATHS`
|
||||
environment variable (comma-separated). Configure which container to restart
|
||||
using `TARGET_CONTAINER` (defaults to `ur_gia`).
|
||||
|
||||
Example:
|
||||
|
||||
WATCH_PATHS=/code/core TARGET_CONTAINER=ur_gia
|
||||
|
||||
Touching a file under the watched path will trigger a restart of the target
|
||||
container; e.g. `touch /code/core/__restart__` will cause the watcher to act.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
@@ -27,21 +38,23 @@ def get_mtime(path):
|
||||
|
||||
|
||||
def restart_ur():
|
||||
"""Restart ur_gia container."""
|
||||
print(f'[{time.strftime("%H:%M:%S")}] Restarting ur_gia...', flush=True)
|
||||
result = subprocess.run(
|
||||
'podman restart ur_gia 2>/dev/null || docker restart ur_gia 2>/dev/null',
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
)
|
||||
"""Restart target container (defaults to `ur_gia`)."""
|
||||
target = os.environ.get('TARGET_CONTAINER', 'ur_gia')
|
||||
print(f'[{time.strftime("%H:%M:%S")}] Restarting {target}...', flush=True)
|
||||
cmd = f'podman restart {target} 2>/dev/null || docker restart {target} 2>/dev/null'
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True)
|
||||
if result.returncode == 0:
|
||||
print(f'[{time.strftime("%H:%M:%S")}] ur_gia restarted', flush=True)
|
||||
print(f'[{time.strftime("%H:%M:%S")}] {target} restarted', flush=True)
|
||||
else:
|
||||
print(f'[{time.strftime("%H:%M:%S")}] restart failed', flush=True)
|
||||
|
||||
|
||||
def main():
|
||||
paths = ['/code/GIA/core', '/code/GIA/app']
|
||||
# In the container the repository is mounted at /code
|
||||
# Allow overriding watched paths via environment variable `WATCH_PATHS`.
|
||||
# Default is `/code/core,/code/app`.
|
||||
paths_env = os.environ.get('WATCH_PATHS', '/code/core,/code/app')
|
||||
paths = [p.strip() for p in paths_env.split(',') if p.strip()]
|
||||
last_mtimes = {}
|
||||
|
||||
for path in paths:
|
||||
|
||||
Reference in New Issue
Block a user