Skip to content

Commit 2b3ace6

Browse files
authored
refactor: Support edge nodes to obtain task stdout and stderr through the central API
1 parent 5027cd3 commit 2b3ace6

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/models/task_meta.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,22 @@ func (m *TaskMeta) HostStrs() ([]string, error) {
292292
}
293293

294294
func (m *TaskMeta) Stdouts() ([]TaskHost, error) {
295+
if !config.C.IsCenter {
296+
path := fmt.Sprintf("/ibex/v1/task/%d/stdout", m.Id)
297+
return poster.GetByUrlsWithResp[[]TaskHost](config.C.CenterApi, path)
298+
}
299+
295300
var ret []TaskHost
296301
err := DB().Table(tht(m.Id)).Where("id=?", m.Id).Select("id", "host", "status", "stdout").Order("ii").Find(&ret).Error
297302
return ret, err
298303
}
299304

300305
func (m *TaskMeta) Stderrs() ([]TaskHost, error) {
306+
if !config.C.IsCenter {
307+
path := fmt.Sprintf("/ibex/v1/task/%d/stderr", m.Id)
308+
return poster.GetByUrlsWithResp[[]TaskHost](config.C.CenterApi, path)
309+
}
310+
301311
var ret []TaskHost
302312
err := DB().Table(tht(m.Id)).Where("id=?", m.Id).Select("id", "host", "status", "stderr").Order("ii").Find(&ret).Error
303313
return ret, err

src/pkg/poster/post.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ func PostByUrlsWithResp[T any](centerApi conf.CenterApi, path string, v interfac
2828

2929
return poster.PostByUrlsWithResp[T](n9eCtx, path, v)
3030
}
31+
32+
func GetByUrlsWithResp[T any](centerApi conf.CenterApi, path string) (t T, err error) {
33+
n9eCtx := NewN9eCtx(centerApi)
34+
35+
return poster.GetByUrls[T](n9eCtx, path)
36+
}

0 commit comments

Comments
 (0)