deploy.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. __author__ = 'lmstack'
  2. #coding=utf-8
  3. import os
  4. import datetime
  5. import pandas as pd
  6. from LIB.BACKEND import DBManager, Log
  7. from sqlalchemy import create_engine
  8. from sqlalchemy.orm import sessionmaker
  9. import time, datetime
  10. import dateutil.relativedelta
  11. import traceback
  12. from LIB.MIDDLE.CellStateEstimation.Common import log
  13. from LIB.MIDDLE.SaftyCenter.Offline import offline_alarm
  14. from urllib import parse
  15. import pymysql
  16. from LIB.BACKEND import DBManager
  17. if __name__ == "__main__":
  18. # 日志配置
  19. now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")
  20. log_path = 'log/' + now_str
  21. if not os.path.exists(log_path):
  22. os.makedirs(log_path)
  23. log = Log.Mylog(log_name='saftyCenter_offline', log_level = 'info')
  24. log.set_file_hl(file_name='{}/info.log'.format(log_path), log_level='info', size=1024* 1024 * 100)
  25. log.set_file_hl(file_name='{}/error.log'.format(log_path), log_level='error', size=1024* 1024 * 100)
  26. logger = log.get_logger()
  27. logger.info("pid is {}".format(os.getpid()))
  28. try:
  29. # 算法参数
  30. host='172.16.121.236'
  31. port=3306
  32. db='fastfun'
  33. user='readonly'
  34. password='Fast1234'
  35. db_iotp_engine = create_engine(
  36. "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
  37. user, parse.quote_plus(password), host, port, db
  38. ))
  39. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  40. port=3306
  41. db='qx_cas'
  42. user='qx_algo_rw'
  43. password='qx@123456'
  44. db_qxcas_engine = create_engine(
  45. "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
  46. user, parse.quote_plus(password), host, port, db
  47. ))
  48. host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
  49. port=3306
  50. db='qixiang_manage'
  51. user='qx_query'
  52. password='@Qx_query'
  53. conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
  54. cursor = conn.cursor()
  55. cursor.execute("select qrcode from py_battery where status=3")
  56. res = cursor.fetchall()
  57. ignore_sns = pd.DataFrame(res, columns=['sn'])['sn'].tolist()
  58. logger.info("pid-{} START!".format(os.getpid()))
  59. offline_alarm.offline_alarm(db_iotp_engine, db_qxcas_engine, ignore_sns)
  60. logger.info("pid-{} DONE!".format(os.getpid()))
  61. except:
  62. logger.error(traceback.format_exc)
  63. logger.error("任务运行错误", exc_info=True)
  64. db_iotp_engine.dispose()
  65. db_qxcas_engine.dispose()
  66. cursor.close()
  67. conn.close