分布式处理和脚底板文件

This commit is contained in:
dongchangxi committed 2023-11-09 11:27:00 +08:00
1 parent f4254f0051
commit 2c036235a6
19 files changed
+1932 -56

No files matched your search

+26 -21
View File
@@ -28,10 +28,10 @@ def get_task_distributed():
print("获取需要执行的步骤 next_step",next_step_result)
return next_step_result
#非R11 R12 的主机在执行step2的时候,需要判断当前模型是否需要高精模或者photo3参与建模,如果是的话,该主机不执行这一步
if next_step_result["run_step"] == "step2":
if common.task_need_high_model_or_photo3(next_step_result["task_key"]):
print(f'模型{next_step_result["task_key"]}需要高精模或者photo3参与建模,该主机{hostname}不执行step2')
return "no"
# if next_step_result["run_step"] == "step2":
# if common.task_need_high_model_or_photo3(next_step_result["task_key"]):
# print(f'模型{next_step_result["task_key"]}需要高精模或者photo3参与建模,该主机{hostname}不执行step2')
# return "no"
#taskData = next_step_result #{"hostname":hostname,"run_step":next_step,"task_distributed_id":result["id"],"task_key":result["task_key"]}
flagRes = update_main_and_add_detail(next_step_result)
if flagRes == "error":
@@ -42,24 +42,27 @@ def get_task_distributed():
else:
return 'no_data'
else:
#R11 R12的主机 可以执行step1 2 3 的任务
#如果R11 R12的主机目前没有正在执行step2,则优先处理step2,
# print("次数",is_run_stepx_nums("step2"))
if is_run_stepx_nums("step2") < 0:
resultData = need_run_step2()
if resultData != "no":
resultData["hostname"] = hostname
flagRes = update_main_and_add_detail(resultData)
if flagRes == "error":
print(f'出现错误,有可能是多个进程获取同一个任务了,重新获取任务去执行了')
return "error"
print(f'任务ID-{resultData["task_key"]}- "执行step2" ')
return resultData
#优先处理step1 和 step3
#R11 R12的主机如果已经有在处理step2了,则不能再处理step2,只能处理step1 step3
resultData = need_run_step_no_step2()
if resultData == "no":
#return "no"
#R11 R12的主机 可以执行step1 2 3 的任务
#如果R11 R12的主机目前没有正在执行step2,则优先处理step2,
# print("次数",is_run_stepx_nums("step2"))
if is_run_stepx_nums("step2") < 2:
resultData = need_run_step2()
if resultData != "no":
resultData["hostname"] = hostname
flagRes = update_main_and_add_detail(resultData)
if flagRes == "error":
print(f'出现错误,有可能是多个进程获取同一个任务了,重新获取任务去执行了')
return "error"
print(f'任务ID-{resultData["task_key"]}- "执行step2" ')
return resultData
#没有任何可执行的
return "no"
resultData["hostname"] = hostname
flagRes = update_main_and_add_detail(resultData)
if flagRes == "error":
@@ -119,7 +122,7 @@ def need_run_stepx(task_distributed_id):
return "step3"
elif result["step"] == "step3":
#这里要将 主任务表的状态改为2,finished_at改为当前时间
update_task_distributed({"id":task_distributed_id,"status":2,"finished_at":time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),"step_last":"step3"})
main_service_db.update_task_distributed({"id":task_distributed_id,"status":2,"finished_at":time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),"step_last":"step3"})
return "no"
return "no"
except Exception as e:
@@ -180,7 +183,7 @@ def need_run_step_no_step2():
#判断是否有正在执行的step2
xstep = need_run_stepx(row["id"])
# print("查询非step2的任务列表",xstep)
if xstep != "step2" and (xstep == "step1" or xstep == "step3"):
if xstep != "step2" and (xstep == "step1"):
#没有正在执行的step2,则返回该任务
return {"hostname":hostname,"run_step":xstep,"task_distributed_id":row["id"],"task_key":row["task_key"]}
return "no"
@@ -201,7 +204,9 @@ def need_run_step_no_step1():
#判断是否有正在执行的step2
xstep = need_run_stepx(row["id"])
#print("查询非step1的任务列表",xstep,row["id"])
if xstep == "step2" or xstep == "step3":
if xstep == "step2":
if common.task_need_high_model_or_photo3(row["task_key"]) and hostname != "R11" and hostname != "R12":
continue
#没有正在执行的step1,则返回该任务
return {"hostname":hostname,"run_step":xstep,"task_distributed_id":row["id"],"task_key":row["task_key"]}
return "no"