|  | @@ -41,7 +41,7 @@ def server_health_check(ecs_client, instance_id):
 | 
	
		
			
				|  |  |              time.sleep(10)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version):
 | 
	
		
			
				|  |  | +async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version, port):
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |      扩容机器并运行新服务
 | 
	
		
			
				|  |  |      :param ecs_client: 购买机器客户端连接
 | 
	
	
		
			
				|  | @@ -49,6 +49,7 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version):
 | 
	
		
			
				|  |  |      :param ess_count: 扩容数量
 | 
	
		
			
				|  |  |      :param max_workers: 线程数
 | 
	
		
			
				|  |  |      :param version: 版本标记
 | 
	
		
			
				|  |  | +    :param port: 后端服务器使用的端口
 | 
	
		
			
				|  |  |      :return:
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |      # 1. 购买机器并启动
 | 
	
	
		
			
				|  | @@ -84,14 +85,15 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version):
 | 
	
		
			
				|  |  |          health_instance_ids = [instance_id for instance_id, _ in health_instances]
 | 
	
		
			
				|  |  |          for server_group_id in longvideoapi_config.server_group_id_list:
 | 
	
		
			
				|  |  |              for instance_id in health_instance_ids:
 | 
	
		
			
				|  |  | -                alb_utils.add_servers_to_server_group(alb_client, server_group_id, instance_id, weight=0)
 | 
	
		
			
				|  |  | +                alb_utils.add_servers_to_server_group(alb_client, server_group_id, instance_id, weight=0, port=port)
 | 
	
		
			
				|  |  |                  logging.info(f"Successfully added instance {instance_id} to server group {server_group_id}.")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          add_weight_list = [(10, 5), (20, 5), (40, 5), (60, 5), (80, 5), (100, 5)]
 | 
	
		
			
				|  |  |          alb_utils.update_server_group_servers_attribute(alb_client,
 | 
	
		
			
				|  |  |                                                     longvideoapi_config.server_group_id_list,
 | 
	
		
			
				|  |  |                                                     health_instance_ids,
 | 
	
		
			
				|  |  | -                                                   add_weight_list)
 | 
	
		
			
				|  |  | +                                                   add_weight_list,
 | 
	
		
			
				|  |  | +                                                   longvideoapi_config.port)
 | 
	
		
			
				|  |  |          logging.info(f"finished instances: {health_instances}, count: {len(health_instances)}")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -148,7 +150,7 @@ def remove_container_image(ecs_client, instance_id, container_name_list):
 | 
	
		
			
				|  |  |              i += 1
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -async def update_instance(ecs_client, alb_client, instance_ids, max_workers, version):
 | 
	
		
			
				|  |  | +async def update_instance(ecs_client, alb_client, instance_ids, max_workers, version, port):
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |      线上机器更新
 | 
	
		
			
				|  |  |      :param ecs_client:
 | 
	
	
		
			
				|  | @@ -156,6 +158,7 @@ async def update_instance(ecs_client, alb_client, instance_ids, max_workers, ver
 | 
	
		
			
				|  |  |      :param instance_ids: instanceId type-list
 | 
	
		
			
				|  |  |      :param max_workers:
 | 
	
		
			
				|  |  |      :param version: 版本标记
 | 
	
		
			
				|  |  | +    :param port: 后端服务器使用的端口
 | 
	
		
			
				|  |  |      :return:
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |      media_index = len(instance_ids)//2
 | 
	
	
		
			
				|  | @@ -167,7 +170,8 @@ async def update_instance(ecs_client, alb_client, instance_ids, max_workers, ver
 | 
	
		
			
				|  |  |          alb_utils.update_server_group_servers_attribute(alb_client=alb_client,
 | 
	
		
			
				|  |  |                                                      server_group_id_list=longvideoapi_config.server_group_id_list,
 | 
	
		
			
				|  |  |                                                      instance_id_list=instance_id_list,
 | 
	
		
			
				|  |  | -                                                    weight_list=[(0, 20)])
 | 
	
		
			
				|  |  | +                                                    weight_list=[(0, 20)],
 | 
	
		
			
				|  |  | +                                                    port=port)
 | 
	
		
			
				|  |  |          logging.info(f"set weight with 0 finished, instances: {instance_id_list}")
 | 
	
		
			
				|  |  |          # 2. 异步移除旧容器并删除旧镜像
 | 
	
		
			
				|  |  |          global remove_container_instances
 | 
	
	
		
			
				|  | @@ -215,7 +219,8 @@ async def update_instance(ecs_client, alb_client, instance_ids, max_workers, ver
 | 
	
		
			
				|  |  |              alb_utils.update_server_group_servers_attribute(alb_client,
 | 
	
		
			
				|  |  |                                                         longvideoapi_config.server_group_id_list,
 | 
	
		
			
				|  |  |                                                         health_instance_ids,
 | 
	
		
			
				|  |  | -                                                       add_weight_list)
 | 
	
		
			
				|  |  | +                                                       add_weight_list,
 | 
	
		
			
				|  |  | +                                                       port)
 | 
	
		
			
				|  |  |              logging.info(f"finished instances: {health_instances}, count: {len(health_instances)}")
 | 
	
		
			
				|  |  |              update_finished_count += len(health_instances)
 | 
	
		
			
				|  |  |              logging.info(f"update finished: {update_finished_count}/{len(instance_ids)}")
 | 
	
	
		
			
				|  | @@ -224,12 +229,13 @@ async def update_instance(ecs_client, alb_client, instance_ids, max_workers, ver
 | 
	
		
			
				|  |  |              sys.exit()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def remove_instances(ecs_client, alb_client, instance_ids):
 | 
	
		
			
				|  |  | +def remove_instances(ecs_client, alb_client, instance_ids, port):
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |      停止并释放机器
 | 
	
		
			
				|  |  |      :param ecs_client:
 | 
	
		
			
				|  |  |      :param alb_client:
 | 
	
		
			
				|  |  |      :param instance_ids: instanceId type-list
 | 
	
		
			
				|  |  | +    :param port: 后端服务器使用的端口
 | 
	
		
			
				|  |  |      :return: None
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |      # 1. 摘流量
 | 
	
	
		
			
				|  | @@ -238,7 +244,8 @@ def remove_instances(ecs_client, alb_client, instance_ids):
 | 
	
		
			
				|  |  |          alb_utils.update_server_group_servers_attribute(alb_client,
 | 
	
		
			
				|  |  |                                                     longvideoapi_config.server_group_id_list,
 | 
	
		
			
				|  |  |                                                     instance_ids,
 | 
	
		
			
				|  |  | -                                                   weight_list)
 | 
	
		
			
				|  |  | +                                                   weight_list,
 | 
	
		
			
				|  |  | +                                                   port)
 | 
	
		
			
				|  |  |      except Exception as e:
 | 
	
		
			
				|  |  |          logging.error(f"Failed to set instance weight: {e}")
 | 
	
		
			
				|  |  |          sys.exit()
 | 
	
	
		
			
				|  | @@ -248,7 +255,7 @@ def remove_instances(ecs_client, alb_client, instance_ids):
 | 
	
		
			
				|  |  |      for server_group_id in longvideoapi_config.server_group_id_list:
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              alb_utils.remove_servers_from_server_group(alb_client=alb_client, server_group_id=server_group_id,
 | 
	
		
			
				|  |  | -                                                   instance_id=instance_ids)
 | 
	
		
			
				|  |  | +                                                   instance_id=instance_ids, port=port)
 | 
	
		
			
				|  |  |              logging.info(f"Successfully removed instances from server group {server_group_id}.")
 | 
	
		
			
				|  |  |          except Exception as e:
 | 
	
		
			
				|  |  |              logging.error(f"Failed to remove instances from server group {server_group_id}: {e}")
 | 
	
	
		
			
				|  | @@ -311,13 +318,13 @@ def main():
 | 
	
		
			
				|  |  |          ess_instance_count = online_instance_count // 2
 | 
	
		
			
				|  |  |          logging.info(f"ess instance count: {ess_instance_count}")
 | 
	
		
			
				|  |  |          asyncio.run(ess_instance(ecs_client=ecs_client, alb_client=alb_client,
 | 
	
		
			
				|  |  | -                                 ess_count=ess_instance_count, max_workers=2, version=version))
 | 
	
		
			
				|  |  | +                                 ess_count=ess_instance_count, max_workers=2, version=version, port=longvideoapi_config.port))
 | 
	
		
			
				|  |  |          logging.info(f"ess instances end!")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          # 3. 原有机器进行更新
 | 
	
		
			
				|  |  |          logging.info(f"update online instances start ...")
 | 
	
		
			
				|  |  |          asyncio.run(update_instance(ecs_client=ecs_client, alb_client=alb_client,
 | 
	
		
			
				|  |  | -                                    instance_ids=online_instance_ids, max_workers=8, version=version))
 | 
	
		
			
				|  |  | +                                    instance_ids=online_instance_ids, max_workers=8, version=version, port=longvideoapi_config.port))
 | 
	
		
			
				|  |  |          logging.info(f"update online instances end!")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          # 4. 停止并释放扩容机器
 |