|
@@ -1,10 +1,13 @@
|
|
|
+from asyncio import current_task
|
|
|
import json
|
|
|
+import time
|
|
|
from turtle import update
|
|
|
from app import crud, models
|
|
|
+from app.common import minio
|
|
|
from app.crud.jm_homework_datasource_relation import get_jm_relations
|
|
|
from app.utils.send_util import *
|
|
|
from sqlalchemy.orm import Session
|
|
|
-from app.common.minio import FileHandler
|
|
|
+from app.common.minio import minio_client
|
|
|
|
|
|
type_dict = {
|
|
|
"Java": "java",
|
|
@@ -92,7 +95,7 @@ def jm_job_create_job(jm_job_info: models.JmJobInfo, db: Session):
|
|
|
af_job = res['data']
|
|
|
crud.create_relation(db, jm_job_info.id,'job', af_job['id'])
|
|
|
send_submit(af_job['id'])
|
|
|
- send_pause(af_job['id'], jm_job_info.status)
|
|
|
+ # on_off_control(af_job['id'],jm_job_info.status)
|
|
|
|
|
|
|
|
|
def jm_job_update_job(jm_job_info: models.JmJobInfo, db: Session):
|
|
@@ -122,7 +125,8 @@ def jm_job_update_job(jm_job_info: models.JmJobInfo, db: Session):
|
|
|
res = send_put('/jpt/af_job', job_relation.af_id, af_job)
|
|
|
af_job = res['data']
|
|
|
send_submit(af_job['id'])
|
|
|
- send_pause(af_job['id'],jm_job_info.status)
|
|
|
+ on_off_control(af_job['id'],jm_job_info.status)
|
|
|
+
|
|
|
|
|
|
def jm_job_submit(jm_job_info: models.JmJobInfo, db: Session):
|
|
|
job_relation = crud.get_af_id(db,jm_job_info.id,'job')
|
|
@@ -135,10 +139,8 @@ def jm_job_submit(jm_job_info: models.JmJobInfo, db: Session):
|
|
|
def red_dag_and_format(jm_homework: models.JmHomework, db: Session):
|
|
|
relations = get_jm_relations(db,jm_homework.id)
|
|
|
node_relation_dict = { relation.node_uuid:relation for relation in relations}
|
|
|
- f = open('./dag' + jm_homework.dag_url)
|
|
|
- lines = f.read()
|
|
|
- result = json.loads(lines)
|
|
|
- f.close()
|
|
|
+ file = minio_client.get_file(jm_homework.dag_url)
|
|
|
+ result = json.loads(file)
|
|
|
edges = result['edges']
|
|
|
t_s = {}
|
|
|
input_num = {}
|
|
@@ -167,7 +169,7 @@ def red_dag_and_format(jm_homework: models.JmHomework, db: Session):
|
|
|
elif node['op'] == 'outputsource':
|
|
|
fileds = node['data']['output_source']
|
|
|
script = '''def main_func (input0, spark,sc):
|
|
|
- input0.write.mode("overwrite").saveAsTable('''+node_relation_dict[node['id']].table+''')'''
|
|
|
+ input0.write.mode("overwrite").saveAsTable("'''+node_relation_dict[node['id']].table+'''")'''
|
|
|
inputs = {}
|
|
|
index = 0
|
|
|
input_list = t_s[node['id']]
|
|
@@ -212,6 +214,18 @@ def red_dag_and_format(jm_homework: models.JmHomework, db: Session):
|
|
|
return json.dumps(res)
|
|
|
|
|
|
def red_python_and_format(jm_homework):
|
|
|
- file_handler = FileHandler("datax")
|
|
|
- file = file_handler.get_file(jm_homework.script_file if jm_homework.script_file else "/python/test.py")
|
|
|
- return file.decode("utf-8")
|
|
|
+ file = minio_client.get_file(jm_homework.script_file if jm_homework.script_file else "/python/test.py")
|
|
|
+ return file.decode("utf-8")
|
|
|
+
|
|
|
+
|
|
|
+def on_off_control(af_job_id: int,status: int):
|
|
|
+ for i in range(0,11):
|
|
|
+ parsed_res = get_job_last_parsed_time(af_job_id)
|
|
|
+ last_parsed_time = parsed_res['data']['last_parsed_time']
|
|
|
+ if last_parsed_time:
|
|
|
+ send_pause(af_job_id,status)
|
|
|
+ print(f"{af_job_id}<==状态修改成功==>{last_parsed_time}")
|
|
|
+ break
|
|
|
+ if i >= 10:
|
|
|
+ raise Exception(f"{af_job_id}==>执行失败")
|
|
|
+ time.sleep(2)
|