"""Projections ETL Decider.""" from garcon.param import StaticParam from flows import config as base_config from flows import runner from flows.flow import FlowBase from flows.theatrical_cuts import config from flows.theatrical_cuts import tasks class Flow(FlowBase): """Theatrical cuts SWF flow class.""" def decider(self, schedule): """Schedule the next appropriate activity for the SWF execution.""" bootstrap = schedule('bootstrap', self.bootstrap) determine_anchor_date = schedule( 'determine_anchor_date', self.determine_anchor_date_activity, requires=[bootstrap]) no_anchor_date = determine_anchor_date.result.get('stop') if no_anchor_date: return download_cuts_to_db = schedule( 'download_cuts_to_db', self.download_cuts_to_db, requires=[determine_anchor_date]) update_db = schedule( 'update_db', self.update_db, requires=[download_cuts_to_db]) archive_dropped_csv = schedule( 'archive_dropped_csv', self.archive_dropped_csv, requires=[update_db]) schedule( 'set_final_status', self.set_final_status, requires=[archive_dropped_csv]) @property def bootstrap(self): """Prepare parameters for flow execution. Returns: Activity: garcon.activity.Activity instance. """ return self.create( name='bootstrap', retry=10, tasks=runner.Sync( tasks.bootstrap.fill( correlation_id='correlation_id', workflow_run_id='execution.run_id', s3_bucket='s3_bucket', s3_key='s3_key'))) @property def determine_anchor_date_activity(self): """Determine the anchor date for a upc. Returns: Activity: garcon.activity.Activity instance. """ return self.create( name='determine_anchor_date', retry=10, tasks=runner.Sync( tasks.determine_anchor_date.fill( correlation_id='correlation_id', upc='upc'))) @property def download_cuts_to_db(self): """Download cuts data from S3 bucket to db. Returns: Activity: garcon.activity.Activity instance. """ return self.create( name='download_cuts_to_db', retry=10, tasks=runner.Sync( tasks.download_cuts_to_db.fill( anchor_date='anchor_date', correlation_id='correlation_id', drop_url='drop_url', upc='upc'))) @property def update_db(self): """Download csv data and update revenue table. Returns: Activity: garcon.activity.Activity instance. """ return self.create( name='update_db', retry=10, tasks=runner.Sync( tasks.update_db.fill( anchor_date='anchor_date', correlation_id='correlation_id', drop_url='drop_url', upc='upc'))) @property def archive_dropped_csv(self): """Accept and archive the dropped csv file. Returns: Activity: garcon.activity.Activity instance. """ return self.create( name='archive_dropped_csv', retry=10, tasks=runner.Sync( tasks.archive_dropped_csv.fill( archive_path=StaticParam(config.S3_ARCHIVE_PATH), bucket=StaticParam(base_config.DATA_BUCKET), correlation_id='correlation_id', drop_url='drop_url'))) @property def set_final_status(self): """Set status INGESTED to the db log. Returns: Activity: garcon.activity.Activity instance. """ return self.create( name='set_final_status', retry=10, tasks=runner.Sync( tasks.set_final_status.fill( correlation_id='correlation_id')))