jinhai-2012 commited on
Commit
fed0197
·
1 Parent(s): f05eb1d

Fix elasticsearch status display (#3487)

Browse files

### What problem does this PR solve?

_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Signed-off-by: jinhai <[email protected]>

Files changed (2) hide show
  1. rag/utils/es_conn.py +3 -1
  2. rag/utils/minio_conn.py +13 -13
rag/utils/es_conn.py CHANGED
@@ -63,7 +63,9 @@ class ESConnection(DocStoreConnection):
63
  return "elasticsearch"
64
 
65
  def health(self) -> dict:
66
- return dict(self.es.cluster.health()) + {"type": "elasticsearch"}
 
 
67
 
68
  """
69
  Table operations
 
63
  return "elasticsearch"
64
 
65
  def health(self) -> dict:
66
+ health_dict = dict(self.es.cluster.health())
67
+ health_dict["type"] = "elasticsearch"
68
+ return health_dict
69
 
70
  """
71
  Table operations
rag/utils/minio_conn.py CHANGED
@@ -55,7 +55,7 @@ class RAGFlowMinio(object):
55
  )
56
  return r
57
  except Exception:
58
- logging.exception(f"Fail put {bucket}/{fnm}:")
59
  self.__open__()
60
  time.sleep(1)
61
 
@@ -63,37 +63,37 @@ class RAGFlowMinio(object):
63
  try:
64
  self.conn.remove_object(bucket, fnm)
65
  except Exception:
66
- logging.exception(f"Fail put {bucket}/{fnm}:")
67
 
68
- def get(self, bucket, fnm):
69
  for _ in range(1):
70
  try:
71
- r = self.conn.get_object(bucket, fnm)
72
  return r.read()
73
  except Exception:
74
- logging.exception(f"Fail put {bucket}/{fnm}:")
75
  self.__open__()
76
  time.sleep(1)
77
  return
78
 
79
- def obj_exist(self, bucket, fnm):
80
  try:
81
  if not self.conn.bucket_exists(bucket):
82
  return False
83
- if self.conn.stat_object(bucket, fnm):
84
  return True
85
- return False
 
86
  except Exception:
87
- logging.exception(f"RAGFlowMinio.obj_exist {bucket}/{fnm} got exception:")
88
- return False
89
-
90
 
91
  def get_presigned_url(self, bucket, fnm, expires):
92
  for _ in range(10):
93
  try:
94
  return self.conn.get_presigned_url("GET", bucket, fnm, expires)
95
  except Exception:
96
- logging.exception(f"Fail put {bucket}/{fnm}:")
97
  self.__open__()
98
  time.sleep(1)
99
  return
@@ -101,11 +101,11 @@ class RAGFlowMinio(object):
101
 
102
  MINIO = RAGFlowMinio()
103
 
104
-
105
  if __name__ == "__main__":
106
  conn = RAGFlowMinio()
107
  fnm = "/opt/home/kevinhu/docgpt/upload/13/11-408.jpg"
108
  from PIL import Image
 
109
  img = Image.open(fnm)
110
  buff = BytesIO()
111
  img.save(buff, format='JPEG')
 
55
  )
56
  return r
57
  except Exception:
58
+ logging.exception(f"Fail to put {bucket}/{fnm}:")
59
  self.__open__()
60
  time.sleep(1)
61
 
 
63
  try:
64
  self.conn.remove_object(bucket, fnm)
65
  except Exception:
66
+ logging.exception(f"Fail to remove {bucket}/{fnm}:")
67
 
68
+ def get(self, bucket, filename):
69
  for _ in range(1):
70
  try:
71
+ r = self.conn.get_object(bucket, filename)
72
  return r.read()
73
  except Exception:
74
+ logging.exception(f"Fail to get {bucket}/{filename}")
75
  self.__open__()
76
  time.sleep(1)
77
  return
78
 
79
+ def obj_exist(self, bucket, filename):
80
  try:
81
  if not self.conn.bucket_exists(bucket):
82
  return False
83
+ if self.conn.stat_object(bucket, filename):
84
  return True
85
+ else:
86
+ return False
87
  except Exception:
88
+ logging.exception(f"Not found: {bucket}/{filename}")
89
+ return False
 
90
 
91
  def get_presigned_url(self, bucket, fnm, expires):
92
  for _ in range(10):
93
  try:
94
  return self.conn.get_presigned_url("GET", bucket, fnm, expires)
95
  except Exception:
96
+ logging.exception(f"Fail to get_presigned {bucket}/{fnm}:")
97
  self.__open__()
98
  time.sleep(1)
99
  return
 
101
 
102
  MINIO = RAGFlowMinio()
103
 
 
104
  if __name__ == "__main__":
105
  conn = RAGFlowMinio()
106
  fnm = "/opt/home/kevinhu/docgpt/upload/13/11-408.jpg"
107
  from PIL import Image
108
+
109
  img = Image.open(fnm)
110
  buff = BytesIO()
111
  img.save(buff, format='JPEG')