def on_state_change(settings): try: tabpy = settings['tabpy'] py_handler = settings['py_handler'] log_info("Loading state from state file") config = util._get_state_from_file(settings['state_file_path']) new_ps_state = TabPyState(config=config) (has_changes, changes) = _get_latest_service_state(settings, new_ps_state) if not has_changes: log_info("Nothing changed, return.") return new_endpoints = new_ps_state.get_endpoints() for object_name in changes['endpoints']: (object_type, object_version, object_path) = changes['endpoints'][object_name] if not object_path and not object_version: # removal log_info("Removing object", uri=object_name) py_handler.manage_request(DeleteObjects([object_name])) cleanup_endpoint_files(object_name, settings['upload_dir']) else: endpoint_info = new_endpoints[object_name] is_update = object_version > 1 if object_type == 'alias': msg = LoadObject(object_name, endpoint_info['target'], object_version, is_update, 'alias') else: local_path = object_path msg = LoadObject(object_name, local_path, object_version, is_update, object_type) py_handler.manage_request(msg) wait_for_endpoint_loaded(py_handler, object_name) # cleanup old version of endpoint files if object_version > 2: cleanup_endpoint_files( object_name, settings['upload_dir'], [object_version, object_version - 1]) except Exception as e: err_msg = format_exception(e, 'on_state_change') log_warning("Error submitting update model request", error=err_msg)
def on_state_change(settings): try: tabpy = settings['tabpy'] py_handler = settings['py_handler'] log_info("Loading state from state file") state_file_path = os.environ['TABPY_STATE_PATH'] config = util._get_state_from_file(state_file_path) new_ps_state = TabPyState(config=config) (has_changes, changes) = _get_latest_service_state(settings, new_ps_state) if not has_changes: log_info("Nothing changed, return.") return new_endpoints = new_ps_state.get_endpoints() for object_name in changes['endpoints']: (object_type, object_version, object_path) = changes['endpoints'][object_name] if not object_path and not object_version: # removal log_info("Removing object", uri=object_name) py_handler.manage_request(DeleteObjects([object_name])) cleanup_endpoint_files(object_name) else: endpoint_info = new_endpoints[object_name] is_update = object_version > 1 if object_type == 'alias': msg = LoadObject(object_name, endpoint_info['target'], object_version, is_update, 'alias') else: local_path = object_path msg = LoadObject(object_name, local_path, object_version, is_update, object_type) py_handler.manage_request(msg) wait_for_endpoint_loaded(py_handler, object_name) # cleanup old version of endpoint files if object_version > 2: cleanup_endpoint_files(object_name, [object_version, object_version - 1]) except Exception as e: err_msg = format_exception(e, 'on_state_change') log_warning("Error submitting update model request", error=err_msg)
def delete_objects(self, object_uris): """Delete one or more objects from the query_objects map""" if isinstance(object_uris, list): deleted = [] for uri in object_uris: deleted.extend(self.delete_objects(uri).uris) return ObjectsDeleted(deleted) elif isinstance(object_uris, str) or isinstance(object_uris, unicode): deleted_obj = self.query_objects.pop(object_uris, None) if deleted_obj: return ObjectsDeleted([object_uris]) else: log_warning("Received message to delete query object " \ "that doesn't exist", object_uris=object_uris) return ObjectsDeleted([]) else: log_error("Unexpected input to delete objects", input=object_uris, info="Input should be list or str. Type: %s" % type(object_uris)) return ObjectsDeleted([])