def __strategy_online(session, strategy_change_history): query = session.query(StrategyOnline) strategy_online_db = query.filter( StrategyOnline.name == strategy_change_history.name).first() if strategy_online_db is None: custom_log.log_error_task('unfind strategy:%s' % strategy_change_history.name) return target_server_list = strategy_online_db.target_server.split('|') parameter_server_list = strategy_online_db.parameter_server.split('|') for index in range(0, len(target_server_list)): server_name = target_server_list[index] parameter_value = parameter_server_list[index] server_model = server_constant.get_server_model(server_name) session_strategy = server_model.get_db_session('strategy') strategy_parameter = StrategyParameter() strategy_parameter.time = date_utils.get_now() strategy_parameter.name = strategy_online_db.name strategy_parameter.value = parameter_value session_strategy.add(strategy_parameter) session_strategy.commit() strategy_online_db.enable = 1 session.merge(strategy_online_db)
def __strategy_offline(session, strategy_change_history): query = session.query(StrategyOnline) strategy_online_db = query.filter( StrategyOnline.name == strategy_change_history.name).first() if strategy_online_db is None: custom_log.log_error_task('unfind strategy:%s' % strategy_change_history.name) return strategy_online_db.enable = 0 session.merge(strategy_online_db) strategy_change_history.parameter_server = strategy_online_db.parameter_server
def md5_check_download_file(server_model, server_file_path, local_file_path): server_md5_value = get_server_file_md5(server_model, server_file_path) local_md5_value = get_local_file_md5(local_file_path) if local_md5_value == server_md5_value: email_content = 'Download Success!Server_Name:%s,File_Name:%s' % \ (server_model.name, server_file_path) custom_log.log_info_task(email_content) return True else: email_content = 'Download Error!Server_Name:%s,File_Name:%s,Server MD5:%s, Local MD5:%s' % \ (server_model.name, server_file_path, server_md5_value, local_md5_value) custom_log.log_error_task(email_content) email_utils.send_email_group_all( '[ERROR]%s:文件下载失败!' % server_model.name, email_content) return False
def start_server_mainframe(server_model): """ 启动MainFrame服务 """ cmd_list = ['cd %s' % server_model.server_path_dict['tradeplat_project_folder'], './script/start.mainframe.sh' ] server_model.run_cmd_str(';'.join(cmd_list)) time.sleep(10) cmd_list = ['cd %s' % server_model.server_path_dict['tradeplat_log_folder'], 'ls *MainFrame*.log' ] log_file_info = server_model.run_cmd_str(';'.join(cmd_list)) log_file_list = [] for log_file_name in log_file_info.split('\n'): if len(log_file_name) > 0: log_file_list.append(log_file_name) log_file_list.sort() log_file_name = log_file_list[-1] filter_date_str = date_utils.get_today_str() if filter_date_str not in log_file_name: custom_log.log_error_task("[Error]start_server_mainframe---today_str:%s, log file:%s" % (filter_date_str, log_file_name)) return False cmd_list = ['cd %s' % server_model.server_path_dict['tradeplat_log_folder'], 'tail -100 %s' % log_file_name ] log_info = server_model.run_cmd_str(';'.join(cmd_list)) try_times_index = 1 while 'TradingFramework start command loop now.' not in log_info and try_times_index <= 10: time.sleep(10) log_info = server_model.run_cmd_str(';'.join(cmd_list)) try_times_index += 1 if try_times_index > 10: return False else: return True