|
7 | 7 | import pathlib
|
8 | 8 | import tomllib
|
9 | 9 | from collections import abc
|
10 |
| -from typing import Any |
| 10 | +from typing import Any, assert_never |
11 | 11 |
|
12 | 12 | from frequenz.channels import Sender
|
13 | 13 | from frequenz.channels.util import FileWatcher
|
@@ -84,13 +84,31 @@ async def run(self) -> None:
|
84 | 84 | await self.send_config()
|
85 | 85 |
|
86 | 86 | async for event in self._file_watcher:
|
87 |
| - if event.type != FileWatcher.EventType.DELETE: |
88 |
| - # Since we are watching the whole parent directory, we need to make sure |
89 |
| - # we only react to events related to the configuration file. |
90 |
| - if event.path == self._config_path: |
| 87 | + # Since we are watching the whole parent directory, we need to make sure |
| 88 | + # we only react to events related to the configuration file. |
| 89 | + if event.path != self._config_path: |
| 90 | + continue |
| 91 | + |
| 92 | + match event.type: |
| 93 | + case FileWatcher.EventType.CREATE: |
| 94 | + _logger.info( |
| 95 | + "%s: The configuration file %s was created, sending new config...", |
| 96 | + self, |
| 97 | + self._config_path, |
| 98 | + ) |
| 99 | + await self.send_config() |
| 100 | + case FileWatcher.EventType.MODIFY: |
91 | 101 | _logger.info(
|
92 |
| - "%s: Update configs, because file %s was modified.", |
| 102 | + "%s: The configuration file %s was modified, sending update...", |
93 | 103 | self,
|
94 | 104 | self._config_path,
|
95 | 105 | )
|
96 | 106 | await self.send_config()
|
| 107 | + case FileWatcher.EventType.DELETE: |
| 108 | + _logger.info( |
| 109 | + "%s: The configuration file %s was deleted, ignoring...", |
| 110 | + self, |
| 111 | + self._config_path, |
| 112 | + ) |
| 113 | + case _: |
| 114 | + assert_never(event.type) |
0 commit comments