77import  pathlib 
88import  tomllib 
99from  collections  import  abc 
10+ from  datetime  import  timedelta 
1011from  typing  import  Any , assert_never 
1112
1213from  frequenz .channels  import  Sender 
@@ -29,13 +30,16 @@ class ConfigManagingActor(Actor):
2930    reading too. 
3031    """ 
3132
33+     # pylint: disable-next=too-many-arguments 
3234    def  __init__ (
3335        self ,
3436        config_path : pathlib .Path  |  str ,
3537        output : Sender [abc .Mapping [str , Any ]],
3638        event_types : abc .Set [EventType ] =  frozenset (EventType ),
3739        * ,
3840        name : str  |  None  =  None ,
41+         force_polling : bool  =  True ,
42+         polling_interval : timedelta  =  timedelta (seconds = 1 ),
3943    ) ->  None :
4044        """Initialize this instance. 
4145
@@ -45,6 +49,9 @@ def __init__(
4549            event_types: The set of event types to monitor. 
4650            name: The name of the actor. If `None`, `str(id(self))` will 
4751                be used. This is used mostly for debugging purposes. 
52+             force_polling: Whether to force file polling to check for changes. 
53+             polling_interval: The interval to poll for changes. Only relevant if 
54+                 polling is enabled. 
4855        """ 
4956        super ().__init__ (name = name )
5057        self ._config_path : pathlib .Path  =  (
@@ -54,6 +61,8 @@ def __init__(
5461        )
5562        self ._output : Sender [abc .Mapping [str , Any ]] =  output 
5663        self ._event_types : abc .Set [EventType ] =  event_types 
64+         self ._force_polling : bool  =  force_polling 
65+         self ._polling_interval : timedelta  =  polling_interval 
5766
5867    def  _read_config (self ) ->  abc .Mapping [str , Any ]:
5968        """Read the contents of the configuration file. 
@@ -89,7 +98,10 @@ async def _run(self) -> None:
8998        # parent directory instead just in case a configuration file doesn't exist yet 
9099        # or it is deleted and recreated again. 
91100        file_watcher  =  FileWatcher (
92-             paths = [self ._config_path .parent ], event_types = self ._event_types 
101+             paths = [self ._config_path .parent ],
102+             event_types = self ._event_types ,
103+             force_polling = self ._force_polling ,
104+             polling_interval = self ._polling_interval ,
93105        )
94106
95107        try :
0 commit comments