Optimization: Made apps and executions way faster

This commit is contained in:
frikky
2021-01-12 18:29:27 +01:00
parent f0a299e69a
commit 34097f971e
11 changed files with 121 additions and 18 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ RUN mkdir /install
WORKDIR /install
COPY requirements.txt /requirements.txt
RUN pip install --prefix="/install" -r /requirements.txt
RUN pip3 install -r /requirements.txt
FROM base
+15 -7
View File
@@ -21,6 +21,7 @@ class AppBase:
# apikey is for the user / org
# authorization is for the specific workflow
self.url = os.getenv("CALLBACK_URL", "https://shuffler.io")
self.base_url = os.getenv("BASE_URL", "https://shuffler.io")
self.action = os.getenv("ACTION", "")
self.authorization = os.getenv("AUTHORIZATION", "")
self.current_execution_id = os.getenv("EXECUTIONID", "")
@@ -30,6 +31,9 @@ class AppBase:
if isinstance(self.action, str):
self.action = json.loads(self.action)
if len(self.base_url) == 0:
self.base_url = self.url
# FIXME: Add more info like logs in here.
# Docker logs: https://forums.docker.com/t/docker-logs-inside-the-docker-container/68190/2
def send_result(self, action_result, headers, stream_path):
@@ -38,7 +42,7 @@ class AppBase:
# I wonder if this actually works
self.logger.info("Before last stream result")
url = "%s%s" % (self.url, stream_path)
url = "%s%s" % (self.base_url, stream_path)
print("URL: %s" % url)
try:
ret = requests.post(url, headers=headers, json=action_result)
@@ -53,7 +57,7 @@ class AppBase:
action_result["status"] = "FAILURE"
action_result["result"] = "POST error: %s" % e
self.logger.info("Before typeerror stream result")
ret = requests.post("%s%s" % (self.url, stream_path), headers=headers, json=action_result)
ret = requests.post("%s%s" % (self.base_url, stream_path), headers=headers, json=action_result)
self.logger.info("Result: %d" % ret.status_code)
if ret.status_code != 200:
self.logger.info(ret.text)
@@ -536,7 +540,7 @@ class AppBase:
# FIXME: Shouldn't skip this, but it's good for minimzing API calls
#try:
# ret = requests.post("%s%s" % (self.url, stream_path), headers=headers, json=action_result)
# ret = requests.post("%s%s" % (self.base_url, stream_path), headers=headers, json=action_result)
# self.logger.info("Workflow: %d" % ret.status_code)
# if ret.status_code != 200:
# self.logger.info(ret.text)
@@ -560,7 +564,7 @@ class AppBase:
self.logger.info("Before FULLEXEC stream result")
ret = requests.post(
"%s/api/v1/streams/results" % (self.url),
"%s/api/v1/streams/results" % (self.base_url),
headers=headers,
json=tmpdata
)
@@ -568,8 +572,12 @@ class AppBase:
if ret.status_code == 200:
fullexecution = ret.json()
else:
self.logger.info("Error: Data: ", ret.json())
self.logger.info("Error with status code for results. Crashing because ACTION_RESULTS or WORKFLOW_VARIABLE can't be handled. Status: %d" % ret.status_code)
try:
self.logger.info("Error: Data: ", ret.json())
self.logger.info("Error with status code for results. Crashing because ACTION_RESULTS or WORKFLOW_VARIABLE can't be handled. Status: %d" % ret.status_code)
except json.decoder.JSONDecodeError:
pass
action_result["result"] = "Bad result from backend: %d" % ret.status_code
self.send_result(action_result, headers, stream_path)
return
@@ -1322,7 +1330,7 @@ class AppBase:
action_result["result"] = tmpresult
action_result["status"] = "FAILURE"
try:
ret = requests.post("%s%s" % (self.url, stream_path), headers=headers, json=action_result)
ret = requests.post("%s%s" % (self.base_url, stream_path), headers=headers, json=action_result)
self.logger.info("Result: %d" % ret.status_code)
if ret.status_code != 200:
self.logger.info(ret.text)
+2 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
NAME=shuffle-app_sdk
VERSION=0.8.51
VERSION=0.8.52
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION
@@ -8,6 +8,7 @@ docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.
#docker push frikky/$NAME:$VERSION
#docker push docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION
#docker push ghcr.io/frikky/$NAME:$VERSION
#docker tag ghcr.io/frikky/$NAME:$VERSION frikky/shuffle:app_sdk
docker push frikky/shuffle:app_sdk
docker push ghcr.io/frikky/$NAME:$VERSION
+1 -1
View File
@@ -1,2 +1,2 @@
requests
urllib3
requests