Skip to content

Commit

Permalink
faasmctl: bump version and use task to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Jul 17, 2023
1 parent f106e86 commit ab9c9bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
black==22.3.0
faasmctl==0.3.6
faasmctl==0.4.2
flake8==3.9.2
invoke>=2.0.0
numpy==1.22.0
Expand Down
31 changes: 8 additions & 23 deletions tasks/func.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
from faasmtools.build import FAASM_LOCAL_DIR
from faasmtools.endpoints import (
get_faasm_invoke_host_port,
get_faasm_upload_host_port,
get_knative_headers,
)

import requests
from base64 import b64encode
from os.path import join
from faasmctl.util.invoke import invoke_wasm
from faasmctl.util.upload import upload_python
from faasmtools.build import FAASM_LOCAL_DIR
from invoke import task
from os import makedirs, listdir
from os.path import join
from shutil import copy
from tasks.env import CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, PROJ_ROOT

Expand All @@ -23,7 +18,6 @@ def uploadpy(ctx, func, local=False):
"""
Upload the given Python function
"""
host, port = get_faasm_upload_host_port()
src_file = join(PY_FUNC_DIR, "{}.py".format(func))

if local:
Expand All @@ -35,10 +29,7 @@ def uploadpy(ctx, func, local=False):
print("Copying function {} {} -> {}".format(func, src_file, dest_file))
copy(src_file, dest_file)
else:
url = "http://{}:{}/p/{}/{}".format(host, port, "python", func)
response = requests.put(url, data=open(src_file, "rb"))

print("Response ({}): {}".format(response.status_code, response.text))
upload_python(func, src_file)


@task
Expand All @@ -59,8 +50,6 @@ def invoke(ctx, user, func, input_data=None):
"""
Invoke a python function on a Faasm cluster
"""
host, port = get_faasm_invoke_host_port()
url = "http://{}:{}".format(host, port)
data = {
"user": CPYTHON_FUNC_USER,
"function": CPYTHON_FUNC_NAME,
Expand All @@ -74,11 +63,7 @@ def invoke(ctx, user, func, input_data=None):
"utf-8"
)

headers = get_knative_headers()
response = requests.post(url, json=data, headers=headers)

if response.status_code != 200:
print("Error ({}):\n{}".format(response.status_code, response.text))
exit(1)
# Invoke message
response = invoke_wasm(data)

print("Success:\n{}".format(response.text))
print("Success:\n{}".format(response.messageResults[0].outputData))

0 comments on commit ab9c9bc

Please sign in to comment.