def run()

in core/actionProxy/owplatform/knative.py [0:0]


    def run(self):
        response = None
        message = flask.request.get_json(force=True, silent=True) or {}
        request_headers = flask.request.headers
        dedicated_runtime = False

        if message and not isinstance(message, dict):
            return self._run_error()

        try:
            # don't process init data if it is not a stem cell
            if hasInitData(message) and not isStemCell():
                raise NonStemCellInitError()

            # if it is a dedicated runtime and is uninitialized, then init from environment
            if not isStemCell() and self.proxy.initialized is False:
                message['init'] = createInitDataFromEnvironment()
                dedicated_runtime = True

            preProcessRequest(message)
            if hasInitData(message) and hasActivationData(message) and not dedicated_runtime:
                self.initCode(message)
                removeInitData(message)
                response = self.runCode(message)
                response = postProcessResponse(request_headers, response)
            elif hasInitData(message) and not dedicated_runtime:
                response = self.initCode(message)
            elif hasActivationData(message) and not dedicated_runtime:
                response = self.runCode(message)
                response = postProcessResponse(request_headers, response)
            else:
                # This is for the case when it is a dedicated runtime, but has not yet been
                # initialized from the environment
                if dedicated_runtime and self.proxy.initialized is False:
                    self.initCode(message)
                    removeInitData(message)
                response = self.runCode(message)
                response = postProcessResponse(request_headers, response)
        except Exception as e:
            response = flask.jsonify({'error': str(e)})
            response.status_code = 404

        return response