1+ """
2+ Module containing the base class for extractors.
3+ """
14# Copyright 2021 Cognite AS
25#
36# Licensed under the Apache License, Version 2.0 (the "License");
3538
3639
3740class ReloadConfigAction (Enum ):
41+ """
42+ Enum for actions to take when a config file is reloaded.
43+ """
44+
3845 DO_NOTHING = 1
3946 REPLACE_ATTRIBUTE = 2
4047 SHUTDOWN = 3
@@ -126,8 +133,10 @@ def __init__(
126133
127134 def _initial_load_config (self , override_path : str | None = None ) -> None :
128135 """
129- Load a configuration file, either from the specified path, or by a path specified by the user in a command line
130- arg. Will quit further execution of no path is given.
136+ Load a configuration file.
137+
138+ Either from the specified path, or from a path specified by the user in a command line arg. Will quit further
139+ execution if no path is specified.
131140
132141 Args:
133142 override_path: Optional override for file path, ie don't parse command line arguments
@@ -150,6 +159,11 @@ def config_refresher() -> None:
150159 Thread (target = config_refresher , name = "ConfigReloader" , daemon = True ).start ()
151160
152161 def reload_config_callback (self ) -> None :
162+ """
163+ If the reload_config_action was set to CALLBACK, this method will be called when the config file is reloaded.
164+
165+ This method should be overridden in subclasses to provide custom behavior when the config file is reloaded.
166+ """
153167 self .logger .error ("Method for reloading configs has not been overridden in subclass" )
154168
155169 def _reload_config (self ) -> None :
@@ -173,9 +187,11 @@ def _reload_config(self) -> None:
173187
174188 def _load_state_store (self ) -> None :
175189 """
176- Searches through the config object for a StateStoreConfig. If found, it will use that configuration to generate
177- a state store, if no such config is found it will either create a LocalStateStore or a NoStateStore depending
178- on whether the ``use_default_state_store`` argument to the constructor was true or false.
190+ Searches through the config object for a StateStoreConfig.
191+
192+ If found, it will use that configuration to generate a state store, if no such config is found it will either
193+ create a LocalStateStore or a NoStateStore depending on whether the ``use_default_state_store`` argument to the
194+ constructor was true or false.
179195
180196 Either way, the state_store attribute is guaranteed to be set after calling this method.
181197 """
@@ -213,7 +229,7 @@ def recursive_find_state_store(d: dict[str, Any]) -> StateStoreConfig | None:
213229
214230 def _report_success (self ) -> None :
215231 """
216- Called on a successful exit of the extractor
232+ Called on a successful exit of the extractor.
217233 """
218234 if self .extraction_pipeline :
219235 self .logger .info ("Reporting new successful run" )
@@ -227,7 +243,7 @@ def _report_success(self) -> None:
227243
228244 def _report_error (self , exception : BaseException ) -> None :
229245 """
230- Called on an unsuccessful exit of the extractor
246+ Called on an unsuccessful exit of the extractor.
231247
232248 Args:
233249 exception: Exception object that caused the extractor to fail
@@ -250,7 +266,6 @@ def __enter__(self) -> "Extractor":
250266 Returns:
251267 self
252268 """
253-
254269 if str (os .getenv ("COGNITE_FUNCTION_RUNTIME" , False )).lower () != "true" :
255270 # Environment Variables
256271 env_file_found = load_dotenv (dotenv_path = "./.env" , override = True )
@@ -357,10 +372,11 @@ def __exit__(
357372
358373 def run (self ) -> None :
359374 """
360- Run the extractor. Ensures that the Extractor is set up correctly (``run`` called within a ``with``) and calls
361- the ``run_handle``.
375+ Run the extractor.
376+
377+ Ensures that the Extractor is set up correctly (``run`` called within a ``with``) and calls the ``run_handle``.
362378
363- Can be overrided in subclasses.
379+ Can be overriden in subclasses.
364380 """
365381 if not self .started :
366382 raise ValueError ("You must run the extractor in a context manager" )
@@ -371,12 +387,30 @@ def run(self) -> None:
371387
372388 @classmethod
373389 def get_current_config (cls ) -> CustomConfigClass :
390+ """
391+ Get the current configuration singleton.
392+
393+ Returns:
394+ The current configuration singleton
395+
396+ Raises:
397+ ValueError: If no configuration singleton has been created, meaning no config file has been loaded.
398+ """
374399 if Extractor ._config_singleton is None : # type: ignore
375400 raise ValueError ("No config singleton created. Have a config file been loaded?" )
376401 return Extractor ._config_singleton # type: ignore
377402
378403 @classmethod
379404 def get_current_statestore (cls ) -> AbstractStateStore :
405+ """
406+ Get the current state store singleton.
407+
408+ Returns:
409+ The current state store singleton
410+
411+ Raises:
412+ ValueError: If no state store singleton has been created, meaning no state store has been loaded.
413+ """
380414 if Extractor ._statestore_singleton is None :
381415 raise ValueError ("No state store singleton created. Have a state store been loaded?" )
382416 return Extractor ._statestore_singleton
0 commit comments