ad_hourly.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from model.DateUtils import DateUtils
  2. from app.api_data.tx_ad_cost import get_cost
  3. from app.etl.dw import dw_image_cost_day
  4. import time
  5. from model.DingTalkUtils import DingTalkUtils
  6. import logging
  7. from logging import handlers
  8. import threading
  9. du = DateUtils()
  10. def hourly_run():
  11. # 广告数据
  12. get_cost.hourly()# 广告相关消耗数据
  13. dw_image_cost_day.hourly()
  14. if __name__ == '__main__':
  15. logging.basicConfig(
  16. handlers=[
  17. logging.handlers.RotatingFileHandler('./log/ad_hourly.log',
  18. maxBytes=10 * 1024 * 1024,
  19. backupCount=5,
  20. encoding='utf-8')
  21. , logging.StreamHandler() # 供输出使用
  22. ],
  23. level=logging.INFO,
  24. format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
  25. )
  26. logging.info('广告素材任务,开始')
  27. st = time.time()
  28. hourly_thread=threading.Thread(target=hourly_run)
  29. hourly_thread.daemon=True
  30. hourly_thread.start()
  31. while 1:
  32. if time.time()-st > 3000:
  33. logging.info('线程运行超过50分钟,强制停止')
  34. break
  35. if not hourly_thread.is_alive():
  36. break
  37. if int(time.time()-st)>1500:
  38. DingTalkUtils().send(f"小时任务耗时{int(time.time()-st)}秒",phone="15168342316")
  39. logging.info('广告素材任务,结束')