def process_match(): match_id = request.args.get('match_id') #match_id = matches.get_match_to_process() p('"Processing" match {} due to direct query'.format(match_id)) match = steam_api.get_match_details(match_id=match_id) hooks.process(match=match) matches.mark_as_processed(match_id) return 'Done'
def process_matches_in_background(dota_api, matches, hooks): p('Process matches started!') def process_one(): match_id = matches.get_match_to_process() p('"Processing" match {}'.format(match_id)) match = dota_api.get_match_details(match_id=match_id) hooks.process(match=match) matches.mark_as_processed(match_id) forever(process_one, 2)
def process_leagues_in_background(leagues, dota_api, matches): p('Process leagues started!') def process_league(league_id): new_matches = dota_api.get_match_history( laegue_id=league_id)['matches'] for match in new_matches: matches.add(match['match_id']) def process_leagues(): tracked = [l['_id'] for l in leagues.list(is_tracked='true') ] # TODO: figure out why True does not work for league_id in tracked: process_league(league_id) forever(process_leagues, 3000) # TODO: read delay from config
def process_one(): match_id = matches.get_match_to_process() p('"Processing" match {}'.format(match_id)) match = dota_api.get_match_details(match_id=match_id) hooks.process(match=match) matches.mark_as_processed(match_id)
def process(self, **context): for name, trigger in self._hooks.items(): try: trigger.process(**context) except Exception as e:# TODO: actually handle exceptions here p(e)