Skip to content

Commit

Permalink
Read input JSON directly where available
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Sep 9, 2020
1 parent c885f5d commit ccf6f86
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/labthings/actions/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import traceback
import uuid

from flask import copy_current_request_context, has_request_context
from flask import request, copy_current_request_context, has_request_context

from ..utilities import TimeoutTracker
from ..schema import LogRecordSchema
from ..deque import Deque

_LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,8 +67,13 @@ def __init__(
if has_request_context():
logging.debug(f"Copying request context to {self._target}")
self._target = copy_current_request_context(self._target)
try:
self.input = request.json
except BadRequest:
self.input = None
else:
logging.debug("No request context to copy")
self.input = None

# Private state properties
self._status: str = "pending" # Task status
Expand All @@ -79,9 +83,6 @@ def __init__(
self._end_time = None # Task end time

# Public state properties
self.input: dict = (
{}
) # Input arguments. TODO: Automate this. Currently manual via Action.dispatch_request
self.progress: int = None # Percent progress of the task
self.data = {} # Dictionary of custom data added during the task
self.log = Deque(
Expand Down Expand Up @@ -369,9 +370,8 @@ def emit(self, record):
:param record:
"""
self.dest.append(LogRecordSchema().dump(record))
self.dest.append(record)
# TODO: think about whether any of the keys are security flaws
# (this is why I don't dump the whole logrecord)


# Backwards compatibility
Expand Down

0 comments on commit ccf6f86

Please sign in to comment.