"""trending_tracks workflow.""" from garcon import runner from activity_detector.flows.base_flow import BaseFlow from activity_detector.flows.trending_tracks import config from activity_detector.flows.trending_tracks.tasks.\ fetch_country_groups import fetch_country_groups from activity_detector.flows.trending_tracks.tasks.\ fetch_last_available_date_per_store \ import fetch_last_available_date_per_store from activity_detector.flows.trending_tracks.tasks.fetch_trending_tracks \ import fetch_trending_tracks from activity_detector.flows.trending_tracks.tasks.get_date_range \ import get_date_range class Flow(BaseFlow): """Class representing the workflow.""" timeout = 2160 * 60 # 36 hours def __init__(self): """Initialize flow object.""" super(Flow, self).__init__( flow_name=config.SWF_FLOW_NAME, version=config.SWF_FLOW_VERSION) def decider(self, schedule, context): """Activity decider. Args: schedule (callable): The scheduler method. """ get_date_range = schedule( 'get_date_range', self.get_date_range) fetch_last_available_date_per_store = schedule( 'fetch_last_available_date_per_store', self.fetch_last_available_date_per_store, requires=[get_date_range]) if 'country_groups' in context: fetch_country_groups = schedule( 'fetch_country_groups_selected', self.fetch_country_groups_selected, requires=[fetch_last_available_date_per_store]) else: fetch_country_groups = schedule( 'fetch_country_groups', self.fetch_country_groups, requires=[fetch_last_available_date_per_store]) schedule( 'fetch_trending_tracks', self.fetch_trending_tracks, requires=[fetch_country_groups]) @property def get_date_range(self): """Get date range.""" return self.create( name='get_date_range', tasks=runner.Sync( get_date_range.fill( namespace='get_date_range'))) @property def fetch_last_available_date_per_store(self): """Fetch last available dates per store.""" return self.create( name='fetch_last_available_date_per_store', tasks=runner.Sync( fetch_last_available_date_per_store.fill( namespace='fetch_last_available_date_per_store'))) @property def fetch_country_groups(self): """Get trending tracks country groups.""" return self.create( name='fetch_country_groups', tasks=runner.Sync( fetch_country_groups.fill( namespace='fetch_country_groups'))) @property def fetch_country_groups_selected(self): """Get trending tracks country groups.""" return self.create( name='fetch_country_groups_selected', tasks=runner.Sync( fetch_country_groups.fill( namespace='fetch_country_groups', country_groups='country_groups' ))) @property def fetch_trending_tracks(self): """Get trending tracks.""" return self.create( name='fetch_trending_tracks', tasks=runner.Sync( fetch_trending_tracks.fill( namespace='fetch_trending_tracks', country_groups='fetch_country_groups.country_groups', top_ten_start_date='get_date_range.top_ten_start_date', top_ten_end_date='get_date_range.top_ten_end_date', all_track_start_date='get_date_range.all_track_start_date', all_track_end_date='get_date_range.all_track_end_date', last_dates_per_store='fetch_last_available_date_per_store.' 'last_dates_per_store'))) @property def fetch_trending_tracks_country_groups(self): """Get trending tracks for country groups.""" return self.create( name='fetch_trending_tracks_country_groups', tasks=runner.Sync( fetch_trending_tracks.fill( namespace='fetch_trending_tracks', country_groups='fetch_country_groups_selected' '.country_groups', top_ten_start_date='get_date_range.top_ten_start_date', top_ten_end_date='get_date_range.top_ten_end_date', all_track_start_date='get_date_range.all_track_start_date', all_track_end_date='get_date_range.all_track_end_date', last_dates_per_store='fetch_last_available_date_per_store.' 'last_dates_per_store')))