def get_session(self, session_id): with self.lock: try: return self.session_cache[session_id] except KeyError: # see if session has been persisted sess = persistence.restore(session_id, XFormSession) if sess: self.new_session(sess) # repopulate in-memory cache return sess else: raise NoSuchSession()
def get_session(self, session_id, override_state=None): logging.debug("Getting session id: " + str(session_id)) with self.get_lock(session_id): logger.info('[locking] get_session got lock for session %s' % session_id) try: logging.debug("Getting session_cache " + str(self.session_cache[session_id])) logging.debug("Getting session_cache state: " + str(self.session_cache[session_id].session_state())) return self.session_cache[session_id] except KeyError: # see if session has been persisted logging.debug("Except key error id: " + str(session_id)) sess = persistence.restore(session_id, XFormSession, override_state) logging.debug("Restored session with id: " + str(session_id)) if sess: logging.debug("Returning new session") self.cache_session(sess) # repopulate in-memory cache return sess else: logging.debug("No such session") raise NoSuchSession() logger.info('[locking] get_session released lock for session %s' % session_id)
parser.add_argument("--parameters", type=str, default=os.environ.get(PARAMETERS_ENV_NAME, "[]")) args = parser.parse_args() parameters = parse_parameters(json.loads(args.parameters)) if parameters.get(DEBUG_PARAMETER): parameters.pop(DEBUG_PARAMETER) DEBUG = True interface_file = importlib.import_module(args.interface_name) user_class = getattr(interface_file, args.interface_name) if args.persistence: user_object = persistence.restore(user_class, parameters, debug=DEBUG) persistence.persist(user_object, parameters.get("push_frequency")) else: user_object = user_class(**parameters) if args.service_type == "MODEL": import model_microservice as seldon_microservice elif args.service_type == "ROUTER": import router_microservice as seldon_microservice elif args.service_type == "TRANSFORMER": import transformer_microservice as seldon_microservice elif args.service_type == "OUTLIER_DETECTOR": import outlier_detector_microservice as seldon_microservice port = int(os.environ.get(SERVICE_PORT_ENV_NAME, DEFAULT_PORT))
parser = argparse.ArgumentParser() parser.add_argument("interface_name",type=str,help="Name of the user interface.") parser.add_argument("api_type",type=str,choices=["REST","GRPC"]) parser.add_argument("--service-type",type=str,choices=["MODEL","ROUTER","TRANSFORMER","COMBINER","OUTLIER_DETECTOR"],default="MODEL") parser.add_argument("--persistence",nargs='?',default=0,const=1,type=int) parser.add_argument("--parameters",type=str,default=os.environ.get(PARAMETERS_ENV_NAME,"[]")) args = parser.parse_args() parameters = parse_parameters(json.loads(args.parameters)) interface_file = importlib.import_module(args.interface_name) user_class = getattr(interface_file,args.interface_name) if args.persistence: user_object = persistence.restore(user_class,parameters) persistence.persist(user_object,parameters.get("push_frequency")) else: user_object = user_class(**parameters) if args.service_type == "MODEL": import model_microservice as seldon_microservice elif args.service_type == "ROUTER": import router_microservice as seldon_microservice elif args.service_type == "TRANSFORMER": import transformer_microservice as seldon_microservice elif args.service_type == "OUTLIER_DETECTOR": import outlier_detector_microservice as seldon_microservice port = int(os.environ.get(SERVICE_PORT_ENV_NAME,DEFAULT_PORT))