Kevin Hu
commited on
Commit
·
35ced66
1
Parent(s):
8aa83b1
add taskexecutor status check (#2038)
Browse files### What problem does this PR solve?
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- api/apps/canvas_app.py +1 -1
- api/apps/system_app.py +18 -0
- rag/svr/task_executor.py +18 -0
api/apps/canvas_app.py
CHANGED
@@ -177,4 +177,4 @@ def test_db_connect():
|
|
177 |
db.close()
|
178 |
return get_json_result(retmsg="Database Connection Successful!")
|
179 |
except Exception as e:
|
180 |
-
return server_error_response(
|
|
|
177 |
db.close()
|
178 |
return get_json_result(retmsg="Database Connection Successful!")
|
179 |
except Exception as e:
|
180 |
+
return server_error_response(e)
|
api/apps/system_app.py
CHANGED
@@ -13,6 +13,8 @@
|
|
13 |
# See the License for the specific language governing permissions and
|
14 |
# limitations under the License
|
15 |
#
|
|
|
|
|
16 |
from flask_login import login_required
|
17 |
|
18 |
from api.db.services.knowledgebase_service import KnowledgebaseService
|
@@ -65,4 +67,20 @@ def status():
|
|
65 |
except Exception as e:
|
66 |
res["redis"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
return get_json_result(data=res)
|
|
|
13 |
# See the License for the specific language governing permissions and
|
14 |
# limitations under the License
|
15 |
#
|
16 |
+
import json
|
17 |
+
|
18 |
from flask_login import login_required
|
19 |
|
20 |
from api.db.services.knowledgebase_service import KnowledgebaseService
|
|
|
67 |
except Exception as e:
|
68 |
res["redis"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
|
69 |
|
70 |
+
try:
|
71 |
+
obj = json.loads(REDIS_CONN.get("TASKEXE"))
|
72 |
+
color = "green"
|
73 |
+
for id in obj.keys():
|
74 |
+
arr = obj[id]
|
75 |
+
if len(arr) == 1:
|
76 |
+
obj[id] = [0]
|
77 |
+
else:
|
78 |
+
obj[id] = [arr[i+1]-arr[i] for i in range(len(arr)-1)]
|
79 |
+
elapsed = max(obj[id])
|
80 |
+
if elapsed > 50: color = "yellow"
|
81 |
+
if elapsed > 120: color = "red"
|
82 |
+
res["task_executor"] = {"status": color, "elapsed": obj}
|
83 |
+
except Exception as e:
|
84 |
+
res["task_executor"] = {"status": "red", "error": str(e)}
|
85 |
+
|
86 |
return get_json_result(data=res)
|
rag/svr/task_executor.py
CHANGED
@@ -23,6 +23,7 @@ import re
|
|
23 |
import sys
|
24 |
import time
|
25 |
import traceback
|
|
|
26 |
from functools import partial
|
27 |
|
28 |
from api.db.services.file2document_service import File2DocumentService
|
@@ -373,11 +374,28 @@ def main():
|
|
373 |
r["id"], tk_count, len(cks), timer() - st))
|
374 |
|
375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
if __name__ == "__main__":
|
377 |
peewee_logger = logging.getLogger('peewee')
|
378 |
peewee_logger.propagate = False
|
379 |
peewee_logger.addHandler(database_logger.handlers[0])
|
380 |
peewee_logger.setLevel(database_logger.level)
|
381 |
|
|
|
|
|
|
|
382 |
while True:
|
383 |
main()
|
|
|
23 |
import sys
|
24 |
import time
|
25 |
import traceback
|
26 |
+
from concurrent.futures import ThreadPoolExecutor
|
27 |
from functools import partial
|
28 |
|
29 |
from api.db.services.file2document_service import File2DocumentService
|
|
|
374 |
r["id"], tk_count, len(cks), timer() - st))
|
375 |
|
376 |
|
377 |
+
def report_status():
|
378 |
+
id = "0" if len(sys.argv) < 2 else sys.argv[1]
|
379 |
+
while True:
|
380 |
+
try:
|
381 |
+
obj = REDIS_CONN.get("TASKEXE")
|
382 |
+
obj = json.load(obj)
|
383 |
+
if id not in obj: obj[id] = []
|
384 |
+
obj[id].append(timer()*1000)
|
385 |
+
obj[id] = obj[id][:-60]
|
386 |
+
REDIS_CONN.set_obj("TASKEXE", obj)
|
387 |
+
except Exception as e:
|
388 |
+
print("[Exception]:", str(e))
|
389 |
+
time.sleep(60)
|
390 |
+
|
391 |
if __name__ == "__main__":
|
392 |
peewee_logger = logging.getLogger('peewee')
|
393 |
peewee_logger.propagate = False
|
394 |
peewee_logger.addHandler(database_logger.handlers[0])
|
395 |
peewee_logger.setLevel(database_logger.level)
|
396 |
|
397 |
+
exe = ThreadPoolExecutor(max_workers=1)
|
398 |
+
exe.submit(report_status)
|
399 |
+
|
400 |
while True:
|
401 |
main()
|