Skip to content

Commit 1402dba

Browse files
SunnyHazealeversn
andauthored
[v0.0.3] fix download issue of processed data (#67)
* [fix] Fixed serving list sync issue. * [task] update `/execution/{task_id}/download` to fix url bug and task registry init bug (#66) --------- Co-authored-by: alever_sn <759636538@qq.com>
1 parent d4eaae7 commit 1402dba

5 files changed

Lines changed: 58 additions & 22 deletions

File tree

backend/app/api/v1/endpoints/tasks.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_execution_log(task_id: str, operator_name: str = Query(None, description
115115
raise HTTPException(500, f"Failed to get task logs: {str(e)}")
116116

117117

118-
@router.get("/execution/{task_id}/download", operation_id="download_task_result", summary="下载任务执行结果文件")
118+
@router.get("/execution/{task_id}/download", operation_id="download_task_result", summary="下载任务执行结果文件,step从0开始计数,想请求第一个算子传step=0")
119119
def download_task_result(task_id: str, step: int = None):
120120
"""
121121
下载任务执行结果文件
@@ -160,15 +160,20 @@ def download_task_result(task_id: str, step: int = None):
160160
# 构建缓存文件路径(使用绝对路径)
161161
from app.core.config import settings
162162
cache_path = settings.CACHE_DIR
163+
cache_task_dir = f"{task_id}_output"
163164
cache_file_prefix = "dataflow_cache_step"
164-
cache_file = os.path.join(cache_path, f"{cache_file_prefix}_step{step}.jsonl")
165+
actual_step_for_json = step + 1
166+
167+
cache_file_name = f"{cache_file_prefix}_step{actual_step_for_json}.jsonl"
168+
169+
cache_file = os.path.join(cache_path, cache_task_dir, cache_file_name)
165170

166171
# 检查文件是否存在
167172
if not os.path.exists(cache_file):
168173
raise HTTPException(404, f"Result file not found for step {step}: {cache_file}")
169174

170175
# 返回文件下载
171-
filename = f"{task_id}_{operator_name}_step{step}.jsonl"
176+
filename = f"{task_id}_{operator_name}_step{actual_step_for_json}.jsonl"
172177
logger.info(f"Downloading file: {cache_file} as {filename}")
173178

174179
return FileResponse(

backend/app/services/task_registry.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,28 @@ def __init__(self, path: str | None = None):
1919
self._ensure()
2020

2121
def _ensure(self):
22-
"""确保注册表文件存在"""
23-
os.makedirs(os.path.dirname(self.path), exist_ok=True)
24-
initial_data = {"tasks": {}}
25-
self._write(initial_data)
26-
22+
# 只在文件不存在时初始化
23+
if not os.path.exists(self.path):
24+
initial_data = {"tasks": {}}
25+
self._write(initial_data)
26+
return
27+
28+
# 文件存在但为空/损坏时兜底(可选)
29+
try:
30+
with open(self.path, "r", encoding="utf-8") as f:
31+
data = json.load(f)
32+
if not isinstance(data, dict) or "tasks" not in data:
33+
self._write({"tasks": {}})
34+
except Exception:
35+
# 读取失败:备份旧文件再重建(推荐)
36+
broken = self.path + f".broken.{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}"
37+
try:
38+
os.replace(self.path, broken)
39+
except Exception:
40+
pass
41+
self._write({"tasks": {}})
42+
43+
2744
def _read(self) -> Dict:
2845
"""读取注册表"""
2946
with open(self.path, "r", encoding="utf-8") as f:

frontend/src/stores/dataflow.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const useDataflow = defineStore('useDataflow', () => {
150150
const servingList = ref([])
151151
const currentServing = ref(null)
152152
const getServingList = async () => {
153-
await proxy.$api.serving.list_serving_instances_api_v1_serving__get().then((res) => {
153+
return await proxy.$api.serving.list_serving_instances_api_v1_serving__get().then((res) => {
154154
if (res.code === 200) {
155155
res.data.forEach((item) => {
156156
item.key = item.id
@@ -162,6 +162,7 @@ export const useDataflow = defineStore('useDataflow', () => {
162162
status: 'warning'
163163
})
164164
}
165+
return res
165166
})
166167
}
167168
const chooseServing = (item) => {

frontend/src/views/manage/dataflow/index.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,22 @@ export default {
610610
}
611611
})
612612
},
613+
pathJoin(...parts) {
614+
return parts
615+
.map((part, index) => {
616+
if (index === 0) {
617+
return part.replace(/\/+$/, '') // 去掉结尾 /
618+
}
619+
return part.replace(/^\/+|\/+$/g, '') // 去掉两边 /
620+
})
621+
.join('/')
622+
},
613623
downloadData(pipeline_idx) {
614624
if (!this.executionInfo.task_id) return
615625
let baseURL = axios.defaults.baseURL
616626
let url =
617-
baseURL +
618-
`/api/v1/tasks/execution/${this.executionInfo.task_id}/download?step=${pipeline_idx - 1}`
627+
this.pathJoin(baseURL,
628+
`/api/v1/tasks/execution/${this.executionInfo.task_id}/download?step=${pipeline_idx - 1}`)
619629
window.open(url, '_blank')
620630
},
621631
selectPipelineCallback() {

frontend/src/views/manage/serving/index.vue

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@
115115
</template>
116116

117117
<script>
118-
import { mapState } from 'pinia'
118+
import { mapActions, mapState } from 'pinia'
119119
import { useAppConfig } from '@/stores/appConfig'
120120
import { useTheme } from '@/stores/theme'
121+
import { useDataflow } from '@/stores/dataflow';
121122
122123
export default {
123124
data() {
@@ -167,6 +168,9 @@ export default {
167168
this.getServingList()
168169
},
169170
methods: {
171+
...mapActions(useDataflow, {
172+
getGlobalServingList: 'getServingList',
173+
}),
170174
getCreateProps() {
171175
this.$api.serving.list_serving_classes().then((res) => {
172176
if (res.data) {
@@ -184,16 +188,15 @@ export default {
184188
}
185189
})
186190
},
187-
getServingList() {
188-
this.$api.serving.list_serving_instances_api_v1_serving__get().then((res) => {
189-
if (res.data) {
190-
let servingList = res.data
191-
servingList.forEach((item) => {
192-
this.resetEditParams(item, true)
193-
})
194-
this.servingList = servingList
195-
}
196-
})
191+
async getServingList() {
192+
let res = await this.getGlobalServingList()
193+
if (res.data) {
194+
let servingList = res.data
195+
servingList.forEach((item) => {
196+
this.resetEditParams(item, true)
197+
})
198+
this.servingList = servingList
199+
}
197200
},
198201
formatPropsValue(val) {
199202
if (val === null) return null

0 commit comments

Comments
 (0)