Browse Source

Support python function input

For example:
http POST http://127.0.0.1:7070/v1/executions function_id=<FUNCTION_ID> input:='{"param1": "value1"}' X-Auth-Token:<TOKEN>

Change-Id: I04ead79c22ead5720eaab58f456568a7ed9b23b4
changes/36/474536/3
Lingxian Kong 4 years ago
parent
commit
0d3ba2f7c8
  1. 2
      README.rst
  2. 11
      qinling/api/controllers/v1/execution.py
  3. 2
      runtimes/python2/README.md
  4. 12
      runtimes/python2/server.py

2
README.rst

@ -181,7 +181,7 @@ runtime/function/execution in Qinling.
main()
EOF
$ pip install requests -t ~/qinling_test
$ zip ~/qinling_test/qinling_test.zip ~/qinling_test/*
$ zip -r ~/qinling_test/qinling_test.zip ~/qinling_test/*
.. end

11
qinling/api/controllers/v1/execution.py

@ -76,11 +76,12 @@ class ExecutionsController(rest.RestController):
db_model = db_api.create_execution(params)
self.engine_client.create_execution(
db_model.id, function_id, runtime_id,
input=params.get('input'),
is_sync=is_sync
)
if not func_url:
self.engine_client.create_execution(
db_model.id, function_id, runtime_id,
input=params.get('input'),
is_sync=is_sync
)
if is_sync:
db_model = db_api.get_execution(db_model.id)

2
runtimes/python2/README.md

@ -12,7 +12,7 @@ in their function packages through Qinling API or CLI.
You'll need access to a Docker registry to push the image, by default it's
docker hub. After modification, build a new image and upload to docker hub:
docker build -t USER/python-runtime. && docker push USER/python-runtime
docker build -t USER/python-runtime . && docker push USER/python-runtime
## Using the image in Qinling

12
runtimes/python2/server.py

@ -33,7 +33,7 @@ file_name = ''
def download():
download_url = request.form['download_url']
function_id = request.form['function_id']
token = request.form['token']
token = request.form.get('token')
headers = {}
if token:
@ -67,9 +67,17 @@ def execute():
importer = zipimport.zipimporter(file_name)
module = importer.load_module('main')
input = {}
if request.form:
# Refer to:
# http://werkzeug.pocoo.org/docs/0.12/datastructures/#werkzeug.datastructures.MultiDict
input = request.form.to_dict()
app.logger.debug('Invoking function with input: %s' % input)
start = time.time()
try:
result = module.main()
result = module.main(**input)
except Exception as e:
result = str(e)

Loading…
Cancel
Save