"""Store Specific Youtube Adjustment Workflow.""" from feed_ingestion.flows import base from feed_ingestion.flows.youtube_adjustment import config from feed_ingestion.flows.youtube_adjustment import tasks class Flow(base.FlowBase, base.FlowConfigMixin): """Class representing the workflow.""" def __init__(self): """Initialize flow object.""" super(Flow, self).__init__(config.feed_name, config.feed_version) def decider(self, schedule): """Activity decider. Args: schedule (callable): The scheduler method. """ bootstrap = schedule( 'bootstrap', self.bootstrap) process_files = schedule( 'process_files', self.process_files, requires=[bootstrap]) if process_files.result.get('process_files.rows_added') != 0: schedule( 'send_emails', self.send_emails, requires=[process_files]) @property def bootstrap(self): """Bootstrap initial configuration.""" return self.create( name='bootstrap', tasks=base.SyncRunner( tasks.bootstrap.fill( namespace='bootstrap'))) @property def process_files(self): """Process files found on S3.""" return self.create( name='process_files', tasks=base.SyncRunner( tasks.process_files.fill( namespace='process_files', cms_dict='bootstrap.cms_dict', adjustment_dir='bootstrap.adjustment_dir', s3_root='bootstrap.s3_root', ya_format='bootstrap.ya_format', dev_table='bootstrap.dev_table', prod_table='bootstrap.prod_table', ))) @property def send_emails(self): """Send emails that Adjustments were Updated.""" return self.create( name='send_emails', tasks=base.SyncRunner( tasks.send_emails.fill( namespace='send_emails', prod_table='bootstrap.prod_table', rows_added='process_files.rows_added', report_table='bootstrap.report_table', email_list='bootstrap.email_list', asset_view_table='bootstrap.asset_view_table')))