Add support for python function runtime
This commit is contained in:
16
app.py
16
app.py
@@ -48,7 +48,7 @@ app.register_blueprint(auth, url_prefix='/auth')
|
||||
# https://stackoverflow.com/questions/76886643/linking-two-not-exposed-dokku-apps
|
||||
NODE_API_URL = os.environ.get('NODE_API_URL', 'http://isolator.web:5000/execute')
|
||||
DENO_API_URL = os.environ.get('DENO_API_URL', 'http://deno-isolator.web:5000/execute')
|
||||
|
||||
PYTHON_API_URL = os.environ.get('PYTHON_API_URL', 'http://python-isolator.web:5000/execute')
|
||||
|
||||
def map_isolator_response_to_flask_response(response):
|
||||
"""
|
||||
@@ -84,7 +84,12 @@ async def execute_code():
|
||||
# Extract code and convert request to a format acceptable by Node.js app
|
||||
code = request.json.get('code')
|
||||
runtime = request.json.get('runtime', 'node') # Default to node
|
||||
api_url = DENO_API_URL if runtime == 'deno' else NODE_API_URL
|
||||
if runtime == 'deno':
|
||||
api_url = DENO_API_URL
|
||||
elif runtime == 'python':
|
||||
api_url = PYTHON_API_URL
|
||||
else:
|
||||
api_url = NODE_API_URL
|
||||
|
||||
request_obj = {
|
||||
'method': request.method,
|
||||
@@ -181,7 +186,12 @@ async def execute_http_function(user_id, function):
|
||||
request_data['text'] = request.data.decode('utf-8')
|
||||
|
||||
# Call the Node.js API asynchronously
|
||||
api_url = DENO_API_URL if runtime == 'deno' else NODE_API_URL
|
||||
if runtime == 'deno':
|
||||
api_url = DENO_API_URL
|
||||
elif runtime == 'python':
|
||||
api_url = PYTHON_API_URL
|
||||
else:
|
||||
api_url = NODE_API_URL
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(api_url, json={'code': code, 'request': request_data, 'environment': environment, 'name': function_name}) as response:
|
||||
response_data = await response.json()
|
||||
|
||||
Reference in New Issue
Block a user