Common method to trigger a reload.
(self)
| 79 | self._trigger_reload() |
| 80 | |
| 81 | def _trigger_reload(self): |
| 82 | """Common method to trigger a reload.""" |
| 83 | current_time = time.time() |
| 84 | |
| 85 | # Debounce rapid file changes |
| 86 | if current_time - self._last_modification < self._debounce_delay: |
| 87 | logger.debug(f"Debouncing file change (too soon): {current_time - self._last_modification:.2f}s") |
| 88 | return |
| 89 | |
| 90 | self._last_modification = current_time |
| 91 | logger.info(f"Config file change detected: {self.config_path}") |
| 92 | |
| 93 | # Schedule the reload callback using the stored loop reference |
| 94 | try: |
| 95 | # Use call_soon_threadsafe to schedule the coroutine from a different thread |
| 96 | future = asyncio.run_coroutine_threadsafe(self._handle_config_change(), self.loop) |
| 97 | logger.debug(f"Scheduled config reload task from thread: {future}") |
| 98 | except Exception as e: |
| 99 | logger.error(f"Failed to schedule config reload: {e}") |
| 100 | |
| 101 | async def _handle_config_change(self): |
| 102 | """Handle config change with proper error handling.""" |
no test coverage detected