"""Playlists sharing with Chartmetric Workflow.""" from garcon_contrib.dynamo_feed_status import garcon_feed_status as feed_status from feed_ingestion.flows import base from feed_ingestion.flows.chartmetric_playlists_share import config from feed_ingestion.flows.chartmetric_playlists_share import tasks class Flow(base.FlowBase, base.FlowConfigMixin): """Class representing the workflow.""" def __init__(self): """Initialize flow object.""" super(Flow, self).__init__(feed_name=config.feed_name, version='0.1') self.timeout = 12000 def decider(self, schedule, context): """Activity decider. Args: schedule (callable): The scheduler method. """ bootstrap = schedule('bootstrap', self.bootstrap) load_missing_playlists = schedule( 'load_missing_playlists', self.load_missing_playlists, requires=[bootstrap]) clear_shared_table = schedule( 'clear_shared_table', self.clear_shared_table, requires=[load_missing_playlists]) share_missing_playlists = schedule( 'share_missing_playlists', self.share_missing_playlists, requires=[clear_shared_table]) schedule( 'set_overall_status_ingested', self.set_overall_status, requires=[share_missing_playlists], input={'status': feed_status.STATUS_INGESTED}) @property def bootstrap(self): """Bootstrap initial configuration.""" return self.create( name='bootstrap', tasks=base.SyncRunner( tasks.bootstrap.fill( namespace='bootstrap', date='context_date',))) @property def load_missing_playlists(self): """Get missing playlists.""" return self.create( name='load_missing_playlists', generators=[self.platform_names_generator], tasks=base.AsyncRunner( tasks.load_missing_playlists.fill( namespace='load_missing_playlists', feed_name='bootstrap.feed_name', platform_name='platform_name'))) @property def clear_shared_table(self): """Get missing playlists.""" return self.create( name='clear_shared_table', tasks=base.AsyncRunner( tasks.clear_shared_table.fill( namespace='clear_shared_table', feed_name='bootstrap.feed_name'))) @property def share_missing_playlists(self): """Share missing playlists.""" return self.create( name='share_missing_playlists', generators=[self.platform_names_generator], tasks=base.AsyncRunner( tasks.share_missing_playlists.fill( namespace='share_missing_playlists', feed_name='bootstrap.feed_name', platform_name='platform_name'))) def platform_names_generator(self, context): """Generate parameters for ingestion activities. Args: context (dict): The current context. Yields: dict: Dictionary with a platform name. """ for platform_name in config.platform_names: yield dict(platform_name=platform_name)