Skip to content

Instantly share code, notes, and snippets.

@totosan
Created May 29, 2020 15:43
Show Gist options
  • Save totosan/a5dfacda90658abfdb5a813483734b00 to your computer and use it in GitHub Desktop.
Save totosan/a5dfacda90658abfdb5a813483734b00 to your computer and use it in GitHub Desktop.
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