feat(watcher.node): Add automatic restart, periodic health checks, and safe event emission to Node watcher; improve logging and stat handling
This commit is contained in:
@@ -71,6 +71,37 @@ The `WriteStabilizer` class replaces chokidar's built-in write stabilization:
|
||||
- **Deno**: Works on all versions with `Deno.watchFs()`
|
||||
- **Bun**: Uses Node.js compatibility layer
|
||||
|
||||
### Robustness Features (v6.1.0+)
|
||||
|
||||
The Node.js watcher includes automatic recovery mechanisms:
|
||||
|
||||
**Auto-restart on failure:**
|
||||
- Watchers automatically restart when errors occur
|
||||
- Exponential backoff (1s → 30s max)
|
||||
- Maximum 3 retry attempts before giving up
|
||||
|
||||
**Health check monitoring:**
|
||||
- 30-second periodic health checks
|
||||
- Detects when watched paths disappear
|
||||
- Triggers automatic restart when issues detected
|
||||
|
||||
**Error isolation:**
|
||||
- Subscriber errors don't crash the watcher
|
||||
- All events emitted via `safeEmit()` with try-catch
|
||||
|
||||
**Verbose logging:**
|
||||
- All lifecycle events logged with `[smartwatch]` prefix
|
||||
- Helps debug watcher issues in production
|
||||
|
||||
Example log output:
|
||||
```
|
||||
[smartwatch] Starting watcher for 1 base path(s)...
|
||||
[smartwatch] Started watching: ./test/assets/
|
||||
[smartwatch] Starting health check (every 30s)
|
||||
[smartwatch] Watcher started with 1 active watcher(s)
|
||||
[smartwatch] Health check: 1 watchers active
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user