add taskexecutor status check (#2038)

### What problem does this PR solve?


### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
Kevin Hu
2024-08-21 17:48:00 +08:00
committed by GitHub
parent 9b3f5fd38b
commit 0f95086813
3 changed files with 37 additions and 1 deletions

View File

@ -177,4 +177,4 @@ def test_db_connect():
db.close()
return get_json_result(retmsg="Database Connection Successful!")
except Exception as e:
return server_error_response(str(e))
return server_error_response(e)

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License
#
import json
from flask_login import login_required
from api.db.services.knowledgebase_service import KnowledgebaseService
@ -65,4 +67,20 @@ def status():
except Exception as e:
res["redis"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
try:
obj = json.loads(REDIS_CONN.get("TASKEXE"))
color = "green"
for id in obj.keys():
arr = obj[id]
if len(arr) == 1:
obj[id] = [0]
else:
obj[id] = [arr[i+1]-arr[i] for i in range(len(arr)-1)]
elapsed = max(obj[id])
if elapsed > 50: color = "yellow"
if elapsed > 120: color = "red"
res["task_executor"] = {"status": color, "elapsed": obj}
except Exception as e:
res["task_executor"] = {"status": "red", "error": str(e)}
return get_json_result(data=res)