from concurrent.futures import ThreadPoolExecutor from dataclasses import dataclass from chartmetric_snowflake.generate_data_dictionary import SetupProcessDictionary @dataclass class ChartmetricInvoker(SetupProcessDictionary): def initialize_chartmetric_invoker(self, *args, **kwargs): """ Setup the workflow required to initiate Chartmetric Invoker """ super(ChartmetricInvoker, self).setup_process_dictionary(*args, **kwargs) self.snowflake_utils.log(message=f'Initializing chartmetric Invoker', _level="info") self.check_if_data_updated() return self def check_if_data_updated(self): if not self.is_manual_run: with ThreadPoolExecutor(50) as ThreadPool: for _chartmetric_source in self.process_dictionary[ 'scheduled']: if self.process_dictionary['scheduled'][_chartmetric_source]['UPDATED'] and not \ self.process_dictionary['scheduled'][_chartmetric_source]['REFRESHED']: ThreadPool.submit(self.update_table_with_interpolation, _chartmetric_source) else: self.snowflake_utils.log(message=f"Working on manual data check", _level='info') with ThreadPoolExecutor(50) as ThreadPool: for _chartmetric_source in self.process_dictionary['manual']: try: if self.process_dictionary['manual'][ _chartmetric_source]['REQUIRED']: ThreadPool.submit( self.update_table_with_interpolation, _chartmetric_source) except Exception as e: self.snowflake_utils.log( message= f"Exception generating interpolated values for {_chartmetric_source}: {e}", _level='error') def update_table_with_interpolation(self, __source): self.snowflake_utils.log( message=f"Updating table for {__source} with interpolated data", _level='info') try: self.snow_flake_instance.run_query( query=self.snowflake_utils.generate_data_checker_query( source=__source.upper())) except Exception as e: self.snowflake_utils.log( message= f"Exception generating interpolated values for {__source}: {e}", _level='error')