"""Cable Calculation ETL Decider.""" from garcon_contrib.dynamo_feed_status import garcon_feed_status from garcon.param import StaticParam from flows import runner from flows.cable_calculation import config from flows.cable_calculation import queries from flows.cable_calculation import tasks from flows.flow import DatabaseParam from flows.flow import FlowBase class Flow(FlowBase): """Flow class for the Cable Calculation ETL decider.""" def decider(self, schedule): """Schedule the next appropriate activity for the SWF execution.""" create_temp_table = schedule( 'create_temp_table', self.create_temp_table_activity) unload_calculate_load_temp_table = schedule( 'unload_calculate_load_temp_table', self.unload_calculate_load_temp_table_activity, requires=[create_temp_table]) if unload_calculate_load_temp_table.result.get('stop'): return move_temp_table_to_cable_revenue = schedule( 'move_temp_table_to_cable_revenue', self.move_temp_table_to_cable_revenue_activity, requires=[unload_calculate_load_temp_table]) finalize_etl_status = schedule( 'finalize_etl_status', self.finalize_etl_status_activity, requires=[move_temp_table_to_cable_revenue]) schedule( 'send_notification', self.send_notification_activity, requires=[finalize_etl_status]) @property def create_temp_table_activity(self): """Task description for creating a temp table. Returns: garcon.activity.Activity instance. """ return self.create( name='create_temp_table', retry=10, tasks=runner.Sync( tasks.create_temp_table.fill( correlation_id='correlation_id', create=StaticParam(queries.CREATE_TEMP_TABLE), namespace='create_temp_table', temp_table_name=StaticParam(queries.TEMP_TABLE_NAME)))) @property def unload_calculate_load_temp_table_activity(self): """Save unloaded and calculated data to temp table. Unload data from raw table, calculate split amount and load to temp table with the corresponding split rules applied. Returns: garcon.activity.Activity instance. """ return self.create( name='unload_calculate_load_temp_table', retry=10, tasks=runner.Sync( tasks.unload_calculate_load_temp_table.fill( correlation_id='correlation_id', upcs=DatabaseParam('upcs'), date_start='date_start', date_end='date_end', select_est_dates=StaticParam( queries.SELECT_SALES_DATE_FOR_UPCS), select_dbo=StaticParam( queries.SELECT_GROSS_FROM_THEATRICAL), select=StaticParam(queries.SELECT_FROM_RAW_TABLE), insert=StaticParam(queries.INSERT_TO_TEMP_TABLE), temp_table_name='create_temp_table.table_name'))) @property def move_temp_table_to_cable_revenue_activity(self): """Task description for moving temp table rows to live. Returns: garcon.activity.Activity instance. """ return self.create( name='move_temp_table_to_cable_revenue', retry=10, tasks=runner.Sync( tasks.move_temp_table_to_cable_revenue.fill( correlation_id='correlation_id', date_end='date_end', date_start='date_start', temp_table_name='create_temp_table.table_name', upcs=DatabaseParam('upcs')))) @property def send_notification_activity(self): """Task for notifying any listening apps. Returns: garcon.activity.Activity instance. """ return self.create( name='send_notification', retry=10, tasks=runner.Async( tasks.send_sns.fill( correlation_id='correlation_id', date_end='date_end', date_start='date_start', upcs='upcs'), tasks.queue_build_cache.fill( correlation_id='correlation_id', date_end='date_end', date_start='date_start', upcs='upcs'))) @property def finalize_etl_status_activity(self): """Complete the ETL by setting the status to COMPLETED. Returns: garcon.activity.Activity instance. """ return self.create( name='finalize_etl_status', retry=10, tasks=runner.Async( tasks.set_final_status.fill( correlation_id='correlation_id'), tasks.update_dashboard_status.fill( wflow_name=StaticParam(config.SWF_WORKFLOW_NAME), end_date='date_end', status=StaticParam( garcon_feed_status.STATUS_INGESTED))))