Skip to content

Commit 05b48ac

Browse files
committed
Fixed Action output formatting
1 parent 8ae655d commit 05b48ac

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/labthings/server/view/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from gevent.timeout import Timeout
1616

17+
import logging
18+
1719

1820
class View(MethodView):
1921
"""
@@ -95,18 +97,18 @@ def dispatch_request(self, *args, **kwargs):
9597
# Keep a copy of the raw, unmarshalled JSON input in the task
9698
task.input = request.json
9799

98-
# Get the schema for this action
99-
response_schema = (
100-
getattr(meth, "__apispec__", {}).get("_schema", {}).get(201, ActionSchema())
101-
)
102-
103100
# Wait up to 2 second for the action to complete or error
104101
try:
105102
task.get(block=True, timeout=1)
103+
logging.info("Got Action response quickly")
106104
except Timeout:
107105
pass
108106

109-
return self.represent_response((response_schema.dump(task), 201))
107+
# If the action returns quickly, and returns a valid Response, return it as-is
108+
if task.output and isinstance(task.output, ResponseBase):
109+
return self.represent_response(task.output)
110+
111+
return self.represent_response((ActionSchema().dump(task), 201))
110112

111113

112114
class PropertyView(View):

0 commit comments

Comments
 (0)