better 504 handling

This commit is contained in:
2025-06-23 14:24:13 +02:00
parent 1370bef1f1
commit 033f82eb2b
2 changed files with 177 additions and 24 deletions

View File

@@ -849,9 +849,12 @@ def deploy_stack():
if stack['Name'] == data['name']:
current_app.logger.info(f"Found existing stack: {stack['Name']} (ID: {stack['Id']})")
return jsonify({
'name': stack['Name'],
'id': stack['Id'],
'status': 'existing'
'success': True,
'data': {
'name': stack['Name'],
'id': stack['Id'],
'status': 'existing'
}
})
# If no existing stack found, proceed with creation
@@ -864,7 +867,7 @@ def deploy_stack():
# Add endpointId as a query parameter
params = {'endpointId': endpoint_id}
# Set a longer timeout for stack creation (10 minutes)
# Use a shorter timeout for stack creation initiation (2 minutes)
create_response = requests.post(
url,
headers={
@@ -874,7 +877,7 @@ def deploy_stack():
},
params=params,
json=request_body,
timeout=600 # 10 minutes timeout for stack creation
timeout=120 # 2 minutes timeout for stack creation initiation
)
# Log the response details
@@ -894,15 +897,20 @@ def deploy_stack():
return jsonify({'error': f'Failed to create stack: {error_message}'}), 500
stack_info = create_response.json()
current_app.logger.info(f"Stack creation initiated: {stack_info['Name']} (ID: {stack_info['Id']})")
return jsonify({
'name': stack_info['Name'],
'id': stack_info['Id'],
'status': 'created'
'success': True,
'data': {
'name': stack_info['Name'],
'id': stack_info['Id'],
'status': 'creating'
}
})
except requests.exceptions.Timeout:
current_app.logger.error("Request timed out while deploying stack")
return jsonify({'error': 'Request timed out while deploying stack. The operation may still be in progress.'}), 504
current_app.logger.error("Request timed out while initiating stack deployment")
return jsonify({'error': 'Request timed out while initiating stack deployment. The operation may still be in progress.'}), 504
except Exception as e:
current_app.logger.error(f"Error deploying stack: {str(e)}")
return jsonify({'error': str(e)}), 500