mirror of
https://github.com/tencentmusic/cube-studio.git
synced 2025-02-17 14:40:28 +08:00
代码风格改进
This commit is contained in:
parent
5460502916
commit
a00129e6bf
@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
nohup python watch_workflow.py > workflow.log 2>&1 &
|
||||
nohup python myapp/tools/watch_workflow.py > workflow.log 2>&1 &
|
||||
|
||||
nohup python watch_service.py > service.log 2>&1 &
|
||||
nohup python myapp/tools/watch_service.py > service.log 2>&1 &
|
||||
|
||||
tail -f workflow.log service.log
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
import time, datetime, os
|
||||
from kubernetes import client
|
||||
from kubernetes import watch
|
||||
@ -14,6 +12,7 @@ from myapp.models.model_job import (
|
||||
from myapp.utils.celery import session_scope
|
||||
from myapp.project import push_admin, push_message
|
||||
from myapp.models.model_job import Pipeline
|
||||
|
||||
conf = app.config
|
||||
|
||||
from myapp.utils.py.py_prometheus import Prometheus
|
||||
@ -33,6 +32,7 @@ else:
|
||||
print('no kubeconfig in cluster %s' % cluster)
|
||||
exit(1)
|
||||
|
||||
|
||||
# 推送微信消息
|
||||
# @pysnooper.snoop()
|
||||
def deliver_message(job):
|
||||
@ -64,6 +64,7 @@ def deliver_message(job):
|
||||
if message:
|
||||
push_message(receivers, message)
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def check_has_push(crd, dbsession):
|
||||
# 可能是workflow启动的或者是hp启动的
|
||||
@ -163,7 +164,6 @@ def check_has_push(crd,dbsession):
|
||||
# push_message([task.pipeline.created_by.username],message)
|
||||
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def save_monitoring(pytorchjob, dbsession):
|
||||
try:
|
||||
@ -209,7 +209,6 @@ def save_monitoring(pytorchjob,dbsession):
|
||||
print(e)
|
||||
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def save_history(pytorchjob, dbsession):
|
||||
info_json = json.loads(pytorchjob.info_json)
|
||||
@ -277,6 +276,7 @@ def deal_event(event,crd_info,namespace):
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
@pysnooper.snoop()
|
||||
def listen_crd():
|
||||
crd_info = conf.get('CRD_INFO')['pytorchjob']
|
||||
@ -298,7 +298,7 @@ def listen_crd():
|
||||
except Exception as ee:
|
||||
print(ee)
|
||||
|
||||
|
||||
# 不能使用异步io,因为stream会阻塞
|
||||
if __name__ == '__main__':
|
||||
listen_crd()
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
import time, os
|
||||
from kubernetes import client
|
||||
from kubernetes import watch
|
||||
@ -7,6 +5,7 @@ from myapp.utils.py.py_k8s import K8s
|
||||
from myapp.project import push_message
|
||||
from myapp import app
|
||||
from myapp.utils.celery import session_scope
|
||||
|
||||
conf = app.config
|
||||
|
||||
cluster = os.getenv('ENVIRONMENT', '').lower()
|
||||
@ -24,6 +23,8 @@ else:
|
||||
|
||||
from myapp.models.model_serving import InferenceService
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def listen_service():
|
||||
namespace = conf.get('SERVICE_NAMESPACE')
|
||||
@ -62,8 +63,7 @@ def listen_service():
|
||||
print(ee)
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
# 不能使用异步io,因为stream会阻塞
|
||||
if __name__ == '__main__':
|
||||
listen_service()
|
||||
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
import time, datetime, os
|
||||
from kubernetes import client
|
||||
from kubernetes import watch
|
||||
@ -14,6 +12,7 @@ from myapp.models.model_job import (
|
||||
from myapp.utils.celery import session_scope
|
||||
from myapp.project import push_admin, push_message
|
||||
from myapp.models.model_job import Pipeline
|
||||
|
||||
conf = app.config
|
||||
|
||||
from myapp.utils.py.py_prometheus import Prometheus
|
||||
@ -33,6 +32,7 @@ else:
|
||||
print('no kubeconfig in cluster %s' % cluster)
|
||||
exit(1)
|
||||
|
||||
|
||||
# 推送消息
|
||||
# @pysnooper.snoop()
|
||||
def deliver_message(tfjob):
|
||||
@ -164,7 +164,6 @@ def check_has_push(crd,dbsession):
|
||||
# push_message([task.pipeline.created_by.username],message)
|
||||
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def save_monitoring(tfjob, dbsession):
|
||||
try:
|
||||
@ -210,7 +209,6 @@ def save_monitoring(tfjob,dbsession):
|
||||
print(e)
|
||||
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def save_history(tfjob, dbsession):
|
||||
info_json = json.loads(tfjob.info_json)
|
||||
@ -278,6 +276,7 @@ def deal_event(event,crd_info,namespace):
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
@pysnooper.snoop()
|
||||
def listen_crd():
|
||||
crd_info = conf.get('CRD_INFO')['tfjob']
|
||||
@ -299,7 +298,7 @@ def listen_crd():
|
||||
except Exception as ee:
|
||||
print(ee)
|
||||
|
||||
|
||||
# 不能使用异步io,因为stream会阻塞
|
||||
if __name__ == '__main__':
|
||||
listen_crd()
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
import pysnooper
|
||||
import time, datetime, os
|
||||
from kubernetes import client
|
||||
@ -17,6 +16,7 @@ from myapp.models.model_job import (
|
||||
)
|
||||
|
||||
from myapp.utils.celery import session_scope
|
||||
|
||||
conf = app.config
|
||||
prometheus = Prometheus(conf.get('PROMETHEUS', ''))
|
||||
|
||||
@ -34,6 +34,7 @@ else:
|
||||
print('no kubeconfig in cluster %s' % cluster)
|
||||
exit(1)
|
||||
|
||||
|
||||
# 推送微信消息
|
||||
# @pysnooper.snoop()
|
||||
def deliver_message(workflow, dbsession):
|
||||
@ -80,6 +81,7 @@ def deliver_message(workflow,dbsession):
|
||||
if message:
|
||||
push_message(receivers, message, link)
|
||||
|
||||
|
||||
# 保存workflow记录
|
||||
# @pysnooper.snoop()
|
||||
def save_workflow(crd, dbsession):
|
||||
@ -138,6 +140,7 @@ def save_workflow(crd,dbsession):
|
||||
dbsession.commit()
|
||||
return workflow
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def check_has_push(crd, dbsession):
|
||||
workflow = dbsession.query(Workflow).filter(Workflow.name == crd['name']).filter(Workflow.namespace == crd['namespace']).first()
|
||||
@ -269,7 +272,6 @@ def push_task_time(workflow,dbsession):
|
||||
push_message(receivers, message, link)
|
||||
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def save_monitoring(workflow, dbsession):
|
||||
try:
|
||||
@ -326,7 +328,6 @@ def save_monitoring(workflow,dbsession):
|
||||
print(e)
|
||||
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def save_history(workflow, dbsession):
|
||||
info_json = json.loads(workflow.info_json)
|
||||
@ -338,15 +339,13 @@ def save_history(workflow,dbsession):
|
||||
workflow.info_json = json.dumps(info_json, indent=4, ensure_ascii=False)
|
||||
dbsession.commit()
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def check_crd_exist(group, version, namespace, plural, name):
|
||||
exist_crd = client.CustomObjectsApi().get_namespaced_custom_object(group, version, namespace, plural, name)
|
||||
return exist_crd
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def deal_event(event, workflow_info, namespace):
|
||||
with session_scope(nullpool=True) as dbsession:
|
||||
@ -366,7 +365,6 @@ def deal_event(event,workflow_info,namespace):
|
||||
if status != 'Pending':
|
||||
status = crd_object['status']['phase']
|
||||
|
||||
|
||||
back_object = {
|
||||
"name": crd_object['metadata']['name'],
|
||||
"namespace": crd_object['metadata']['namespace'] if 'namespace' in crd_object['metadata'] else '',
|
||||
@ -397,6 +395,7 @@ def deal_event(event,workflow_info,namespace):
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
# @pysnooper.snoop()
|
||||
def listen_workflow():
|
||||
workflow_info = conf.get('CRD_INFO')['workflow']
|
||||
@ -417,8 +416,7 @@ def listen_workflow():
|
||||
except Exception as ee:
|
||||
print(ee)
|
||||
|
||||
|
||||
# 不能使用异步io,因为stream会阻塞
|
||||
if __name__ == '__main__':
|
||||
listen_workflow()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user