| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 | 
							- from concurrent.futures import ThreadPoolExecutor
 
- import requests
 
- import datetime
 
- import json
 
- import pandas as pd
 
- from sqlalchemy import create_engine
 
- import uuid
 
- import traceback
 
- db_con_str = "mysql+pymysql://%s:%s@%s:%d/%s" % ("data", "hcst@2021", "139.186.27.96", 4000, "jeecg-boot")
 
- engine = create_engine(db_con_str, connect_args={'charset': 'utf8'})
 
- def send_request(account_id):
 
-     # url = 'http://139.186.27.96:31012/ai_historical_missing_material'
 
-     url = 'http://139.186.27.96:31012/ai_historical_missing_material'
 
-     try:
 
-         request_data = json.dumps({"account_id": account_id})
 
-         request = requests.post(url, request_data)
 
-         return json.loads(request.text)
 
-     except Exception:
 
-         return "account_id = %s, request = %s, traceback = %s " % (account_id, request, traceback.format_exc())
 
- # 0、 打印该定时任务被调用的时间
 
- unique_uuid = str(uuid.uuid4())
 
- print("***********", "补充历史遗漏素材-Start, unique_uuid = ", unique_uuid, datetime.datetime.now(), "**************")
 
- # 1、获取已有的账号 , open_program_create 2是不限  1是程序化  0是自定义
 
- sql = """
 
- select account_id from ctop_ai_kuaishou_advertiser_strategy where status = 1 and open_program_create in (0,2)
 
- """
 
- acc_df = pd.read_sql(sql, engine)
 
- acc_list = [int(account_id) for account_id in acc_df['account_id'].unique()]
 
- print(acc_list)
 
- # 2、 5个账户一组进行发送请求
 
- batch_num = 5
 
- for i in range(0, len(acc_list), batch_num):
 
-     if i + batch_num < len(acc_list):
 
-         print(datetime.datetime.now(), tuple(acc_list[i:i + batch_num]))
 
-         with ThreadPoolExecutor(max_workers=batch_num) as pool:
 
-             results = pool.map(send_request, tuple(acc_list[i: i+batch_num]))
 
-             for r in results:
 
-                 print('res = %s' % r)
 
-     else:
 
-         with ThreadPoolExecutor(max_workers=batch_num) as pool:
 
-             print(datetime.datetime.now(), acc_list[i: len(acc_list)])
 
-             results = pool.map(send_request, tuple(acc_list[i: len(acc_list)]))
 
-             for r in results:
 
-                 print('res = %s' % r)
 
- # 3、 打印该定时任务结束的时间
 
- print("***********", "补充历史遗漏素材-End, unique_uuid = ", unique_uuid, datetime.datetime.now(), "**************")
 
 
  |