def aggregate(self): Logger.Info('%s - AggregationController.aggregate - stated' % __name__) for user in self.users: all_data_points_with_actions = [] dc = DashboardsController(user) for dashboard in dc.get_live_dashboard(): for collection in dashboard['collections']: actions = collection['actions'] for data_point in collection['data_points']: all_data_points_with_actions.append({'data_point':data_point, 'actions':actions}) if all_data_points_with_actions: for data_point_with_actions in all_data_points_with_actions: run_aggregator_for_data_point(data_point_with_actions['data_point'], data_point_with_actions['actions']) #Threading removed # finished = 0 # def producer(q, users): # for user in users: # thread = _UserThread(user) # thread.start() # q.put(thread, True) # def consumer(q, users_count): # while finished <= users_count: # thread = q.get(True) # thread.join() # finished += 1 # q = Queue(1) # producer_thread = threading.Thread(target=producer, args=(q, self.users)) # consumer_thread = threading.Thread(target=consumer, args=(q, len(self.users))) # producer_thread.start() # consumer_thread.start() Logger.Info('%s - AggregationController.aggregate - finished' % __name__)
def run(self): finished = 0 def producer(q, data_points_with_actions): for data_point_with_actions in data_points_with_actions: thread = _DataPointThread(data_point_with_actions) thread.start() q.put(thread, True) def consumer(q, data_points_count): while finished <= data_points_count: thread = q.get(True) thread.join() finished += 1 Logger.Info('%s - AggregationController._UserThread.run - started' % __name__) Logger.Debug('%s - AggregationController._UserThread.run - started with user: %s' % (__name__, self.user)) all_data_points_with_actions = [] dc = DashboardsController(self.user) for dashboard in dc.get_live_dashboard(): for collection in dashboard['collections']: actions = collection['actions'] for data_point in collection['data_points']: all_data_points_with_actions.append({'data_point':data_point, 'actions':actions}) if all_data_points_with_actions: q = Queue(1) producer_thread = threading.Thread(target=producer, args=(q, all_data_points_with_actions)) consumer_thread = threading.Thread(target=consumer, args=(q, len(all_data_points_with_actions))) producer_thread.start() consumer_thread.start() Logger.Info('%s - AggregationController._UserThread.run - finished' % __name__)