# -*- coding: utf-8 -*- from ops.mmysql import MysqlBase import logging from multiprocessing import Pool, cpu_count import datetime from mytask.tasks_1004 import * from mytask.tasks_base import * from mytask.tasks_1016 import * from mytask.tasks_2001 import * from config.config import * import sys from ops.plog import define_logger define_logger("/data/logs/data_collect.log") log = logging.getLogger(__name__) def get_event(): sql = f"""SELECT gameid,channelid,method_name FROM methods WHERE in_used=1""" db = MysqlBase(**DB) data = db.query(sql) events = [] if data: for line in data: if line: # gameid, channelid, method_name = line events.append(line) return events def run_tasks(): args = get_event() # args = event_list pool = Pool(processes=cpu_count()) pool.map(simple_work, args) pool.close() pool.join() class CollectGameData(): def __init__(self, times): self.times = times def workflow(self, line): kwargs = {} kwargs['gameid'], kwargs['channelid'], kwargs['event_type'] = line kwargs['date'] = self.times func = f"run_event_{kwargs['event_type']}(kwargs)" log.info(f"run {func} kwargs={kwargs}!") eval(func) def simple_work(line): try: times = sys.argv[1] except: times = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d') cc = CollectGameData(times) cc.workflow(line) if __name__ == "__main__": run_tasks() # try: # times = sys.argv[1] # except: # times = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d') # for line in event_list: # cc = CollectGameData(times) # cc.workflow(line)