fix: cockpit_project_tasks 所有查询放同一个 async with 块
This commit is contained in:
parent
bcd160d38e
commit
eb4f5ce017
@ -9,52 +9,49 @@ if not uid:
|
||||
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
# Get current project from agent_settings
|
||||
# Get current project and tasks in one session
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${uid}$",
|
||||
{"uid": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
|
||||
if not pid:
|
||||
return json.dumps({"tasks": [], "error": "没有当前项目"}, ensure_ascii=False)
|
||||
if not pid:
|
||||
return json.dumps({"tasks": [], "error": "没有当前项目"}, ensure_ascii=False)
|
||||
|
||||
# Get project name
|
||||
pname = ''
|
||||
precs = await sor.sqlExe(
|
||||
"SELECT name FROM sd_projects WHERE id=${pid}$", {"pid": pid})
|
||||
if precs and len(precs) > 0:
|
||||
pname = getattr(precs[0], 'name', '') or ''
|
||||
# Get project name
|
||||
pname = ''
|
||||
precs = await sor.sqlExe(
|
||||
"SELECT name FROM sd_projects WHERE id=${pid}$", {"pid": pid})
|
||||
if precs and len(precs) > 0:
|
||||
pname = getattr(precs[0], 'name', '') or ''
|
||||
|
||||
# Get tasks - filter by tenant_id matching project's org
|
||||
# Use pipeline_task's DB or shared pipeline DB
|
||||
tasks = await sor.sqlExe(
|
||||
"SELECT id, title, state, current_version, created_at, params, role "
|
||||
"FROM pipeline_tasks WHERE tenant_id='0' ORDER BY created_at DESC LIMIT 50",
|
||||
{})
|
||||
# Get tasks
|
||||
tasks = await sor.sqlExe(
|
||||
"SELECT id, title, state, current_version, created_at, params, role "
|
||||
"FROM pipeline_tasks WHERE tenant_id='0' ORDER BY created_at DESC LIMIT 50",
|
||||
{})
|
||||
|
||||
task_list = []
|
||||
for t in tasks:
|
||||
d = {}
|
||||
# Only copy real data fields, skip methods
|
||||
raw = vars(t) if hasattr(t, '__dict__') else {}
|
||||
for k, v in raw.items():
|
||||
if not callable(v) and not k.startswith('_'):
|
||||
# Extract short description from params JSON
|
||||
if k == 'params' and v:
|
||||
try:
|
||||
p = json.loads(v) if isinstance(v, str) else v
|
||||
desc = p.get('description', '') or p.get('input_text', '') or ''
|
||||
d['description'] = desc[:60]
|
||||
except:
|
||||
d['description'] = ''
|
||||
elif k not in ('clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'to_dict'):
|
||||
v_str = str(v) if v is not None else ''
|
||||
d[k] = v_str
|
||||
task_list.append(d)
|
||||
task_list = []
|
||||
for t in tasks:
|
||||
d = {}
|
||||
raw = vars(t) if hasattr(t, '__dict__') else {}
|
||||
for k, v in raw.items():
|
||||
if not callable(v) and not k.startswith('_'):
|
||||
if k == 'params' and v:
|
||||
try:
|
||||
p = json.loads(v) if isinstance(v, str) else v
|
||||
desc = p.get('description', '') or p.get('input_text', '') or ''
|
||||
d['description'] = desc[:60]
|
||||
except:
|
||||
d['description'] = ''
|
||||
elif k not in ('clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'to_dict'):
|
||||
v_str = str(v) if v is not None else ''
|
||||
d[k] = v_str
|
||||
task_list.append(d)
|
||||
|
||||
return json.dumps({
|
||||
"project_name": pname,
|
||||
"project_id": pid,
|
||||
"tasks": task_list
|
||||
}, ensure_ascii=False)
|
||||
return json.dumps({
|
||||
"project_name": pname,
|
||||
"project_id": pid,
|
||||
"tasks": task_list
|
||||
}, ensure_ascii=False)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user