60 lines
1.8 KiB
Plaintext
60 lines
1.8 KiB
Plaintext
tenant_id = (await get_userorgid()) or '0'
|
|
task_id = params_kw.get('task_id', '')
|
|
parent_id = params_kw.get('id', None)
|
|
|
|
if not task_id:
|
|
return json.dumps({"success": False, "message": "缺少task_id"}, ensure_ascii=False)
|
|
|
|
state_icons = {
|
|
'completed': '\u2705',
|
|
'running': '\ud83d\udfe1',
|
|
'failed': '\u274c',
|
|
'waiting': '\u26a0\ufe0f',
|
|
'pending': '\u2b1c',
|
|
'paused': '\u23f8\ufe0f',
|
|
'cancelled': '\ud83d\uded1',
|
|
'skipped': '\u23ed\ufe0f',
|
|
'rejected': '\ud83d\udeab',
|
|
}
|
|
|
|
try:
|
|
result = await pipeline_detail(tenant_id, task_id)
|
|
data = json.loads(result)
|
|
if not data.get('success'):
|
|
return json.dumps([], ensure_ascii=False)
|
|
|
|
steps = data.get('task', {}).get('steps', [])
|
|
tree_nodes = []
|
|
for step in steps:
|
|
step_name = step.get('step_name', '')
|
|
display_name = step.get('display_name', step_name)
|
|
state = step.get('state', 'pending')
|
|
step_config_str = step.get('step_config', '{}')
|
|
|
|
parent_step = ''
|
|
try:
|
|
cfg = json.loads(step_config_str) if isinstance(step_config_str, str) else step_config_str
|
|
parent_step = cfg.get('parent_step', '') or ''
|
|
except:
|
|
pass
|
|
|
|
icon = state_icons.get(state, '\u2b1c')
|
|
label = '{} {} ({})'.format(icon, display_name, state)
|
|
|
|
tree_nodes.append({
|
|
'id': step_name,
|
|
'parent_step': parent_step,
|
|
'label': label,
|
|
'state': state,
|
|
'step_type': step.get('step_type', ''),
|
|
})
|
|
|
|
if parent_id is not None:
|
|
tree_nodes = [n for n in tree_nodes if n['parent_step'] == parent_id]
|
|
else:
|
|
pass
|
|
|
|
return json.dumps(tree_nodes, ensure_ascii=False)
|
|
except Exception as e:
|
|
return json.dumps([], ensure_ascii=False)
|