Sfoglia il codice sorgente

get jupyter update status

liweiquan 1 anno fa
parent
commit
1671ee9808
2 ha cambiato i file con 16 aggiunte e 21 eliminazioni
  1. 14 14
      app/crud/programme.py
  2. 2 7
      app/utils/send_util.py

+ 14 - 14
app/crud/programme.py

@@ -72,10 +72,8 @@ def start_jupyter(db: Session, item: schemas.ProgrammeId):
     if not j_data:
         # send_util.stop_jupyter({'namespace': namespace,'release_name': db_item.release_name})
         raise Exception("启动结构化编码失败")
-    get_programme_status(namespace,db_item.release_name)
     url = f"http://{j_data['host']}{j_data['base_url']}/lab"
-    time.sleep(10)
-    db_item.status = 1
+    db_item.status = 0
     db.commit()
     db.flush()
     db.refresh(db_item)
@@ -111,19 +109,21 @@ def get_programme(db: Session):
     db_items: List[models.Programme] = db.query(models.Programme).filter(models.Programme.project_id == g.project_id).all()
     res = []
     for item in db_items:
+        complete_url =f'http://{host}{item.base_url}/lab'
+        jupyter_status = get_programme_status(complete_url)
+        item.status = jupyter_status
+        db.commit()
+        db.flush()
+        db.refresh(item)
         i_dict = item.to_dict()
-        i_dict.update({"complete_url": f"http://{host}{i_dict['base_url']}/lab"})
-        # send_util.get_jupyter_html(i_dict['complete_url'])
+        i_dict.update({'complete_url': complete_url})
         res.append(i_dict)
     return res
 
 
-def get_programme_status(namespace: str, release_name: str):
-    for i in range(0,11):
-        res = send_util.get_jupyter_status({"namespace":namespace, "filter":release_name})
-        d_list = res['data']
-        if len(d_list) > 0:
-            return True
-        if i >= 10:
-            raise Exception(f"jupyter启动失败")
-        time.sleep(2)
+def get_programme_status(url: str):
+    res_header= send_util.get_jupyter_html(url)
+    # 若为启动状态,则Server中包含Tornado,否则没有启动
+    print(res_header)
+    jupyter_status = 0 if res_header['Server'].find('Tornado') < 0 else 1
+    return jupyter_status

+ 2 - 7
app/utils/send_util.py

@@ -184,13 +184,8 @@ def get_jupyter_status(data):
 
 # 获取jupyter服务状态
 def get_jupyter_html(url):
-    res = requests.get(url=url)
-    print(res.text)
-    # if 'code' in result.keys() and result['code'] == 200:
-    #     return res.json()
-    # else:
-    #     msg = result['msg'] if 'msg' in result.keys() else result
-    #     raise Exception(f'获取jupyter服务状态,请求jupyter端失败-->{msg}')
+    res = requests.post(url=url)
+    return res.headers
 
 # 请求airflow下载依赖
 def post_install_requirements(requirements_str: str,target_path: str):