Created
May 29, 2020 15:43
-
-
Save totosan/acf5b3405c37c7eb10f52b600d2e2da6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import inspect | |
import importlib.util as imp | |
import logging | |
import sys | |
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'deploy')) | |
script_location = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'deploy/score.py') | |
driver_module_spec = imp.spec_from_file_location('service_driver', script_location) | |
driver_module = imp.module_from_spec(driver_module_spec) | |
driver_module_spec.loader.exec_module(driver_module) | |
def run(http_body, request_headers): | |
global run_supports_request_headers | |
arguments = {run_input_parameter_name: http_body} | |
if run_supports_request_headers: | |
arguments["request_headers"] = request_headers | |
return_obj = driver_module.run(**arguments) | |
return return_obj | |
def init(): | |
global run_input_parameter_name | |
global run_supports_request_headers | |
run_args = inspect.signature(driver_module.run).parameters.keys() | |
run_args_list = list(run_args) | |
run_input_parameter_name = run_args_list[0] if run_args_list[0] != "request_headers" else run_args_list[1] | |
run_supports_request_headers = "request_headers" in run_args_list | |
driver_module.init() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment