def __init__(self): """ Initializes the Model Instance Endpoint service """ initializeEndpointController(self, model_instance_endpoint_controller) self.app = cx.FlaskApp('mistk_server') self.app.app.json_encoder = datautils.PresumptiveJSONEncoder self.app.add_api(self._load_api_spec()) self.http_server = None self._state_machine = None self._model = None self._current_task = None self._status_lock = RWLock() self._task_lock = RWLock() self._response_queue = Queue() self._old_tasks = list() self._thread_pool = ThreadPoolExecutor() info = ObjectInfo('ModelInstanceStatus', resource_version=1) self._status = ModelInstanceStatus(object_info=info, state='started')
def update_state(self, state=None, payload=None): """ Updates the state of the ModelEndpointService :param state: The new state. If not given, the current state will be used. :param payload: Additional data to attach to the state """ try: with self._status_lock.writer_lock: state = state or self._status.state ver = self._status.object_info.resource_version + 1 info = ObjectInfo('ModelInstanceStatus', resource_version=ver) self._status = ModelInstanceStatus(info, state=state, payload=payload) watch_manager.notify_watch('status', item=self._status) except RuntimeError as inst: msg = "Error while updating state of the ModelEndpointService. %s" % str(inst) logger.exception(msg) return ServiceError(500, msg), 500