fix: cockpit_project_tasks 所有查询放同一个 async with 块
This commit is contained in:
parent
bcd160d38e
commit
eb4f5ce017
@ -9,38 +9,35 @@ 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:
|
||||
if not pid:
|
||||
return json.dumps({"tasks": [], "error": "没有当前项目"}, ensure_ascii=False)
|
||||
|
||||
# Get project name
|
||||
pname = ''
|
||||
precs = await sor.sqlExe(
|
||||
# Get project name
|
||||
pname = ''
|
||||
precs = await sor.sqlExe(
|
||||
"SELECT name FROM sd_projects WHERE id=${pid}$", {"pid": pid})
|
||||
if precs and len(precs) > 0:
|
||||
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(
|
||||
# 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:
|
||||
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
|
||||
@ -53,8 +50,8 @@ for t in tasks:
|
||||
d[k] = v_str
|
||||
task_list.append(d)
|
||||
|
||||
return json.dumps({
|
||||
return json.dumps({
|
||||
"project_name": pname,
|
||||
"project_id": pid,
|
||||
"tasks": task_list
|
||||
}, ensure_ascii=False)
|
||||
}, ensure_ascii=False)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user