Fix some compose panel bugs and reload workers when changed

This commit is contained in:
2026-02-16 13:39:48 +00:00
parent 9ce50a3053
commit 8ca1695fab
7 changed files with 177 additions and 25 deletions

View File

@@ -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)