新建服务器记录后延迟30秒更新公网ip等信息且设置最大重试30次
This commit is contained in:
parent
24a8aa7567
commit
819b195a67
@ -1285,7 +1285,7 @@ def create_aliyun_server(order_name):
|
||||
jingrow.db.commit()
|
||||
|
||||
# 延迟60秒执行update_server_record来更新服务器详细信息
|
||||
time.sleep(60)
|
||||
time.sleep(30)
|
||||
jingrow.enqueue(
|
||||
"jcloud.api.aliyun_server_light.update_server_record",
|
||||
instance_ids=json.dumps([instance_id]),
|
||||
@ -1380,10 +1380,22 @@ def update_server_record(instance_ids):
|
||||
|
||||
instance_info = instances[0] # 取第一个实例
|
||||
|
||||
# 更新public_ip
|
||||
# 获取公网IP(最多重试30次)
|
||||
public_ip = instance_info.get('public_ip_address')
|
||||
if public_ip:
|
||||
server.public_ip = public_ip
|
||||
if not public_ip:
|
||||
for retry in range(30):
|
||||
time.sleep(10)
|
||||
retry_details = get_aliyun_instance_details(instance_ids, region_id)
|
||||
if retry_details and retry_details.get('success'):
|
||||
retry_instances = retry_details.get('data', {}).get('instances', [])
|
||||
if retry_instances and retry_instances[0].get('public_ip_address'):
|
||||
public_ip = retry_instances[0].get('public_ip_address')
|
||||
break
|
||||
else:
|
||||
jingrow.log_error(f"获取公网IP失败-{instance_id}", f"实例 {instance_id} 在30次重试后仍未获取到公网IP")
|
||||
return {"success": False, "message": f"实例 {instance_id} 在30次重试后仍未获取到公网IP"}
|
||||
|
||||
server.public_ip = public_ip
|
||||
|
||||
# 更新end_date(从expired_time转换)
|
||||
expired_time = instance_info.get('expired_time')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user