Skip to content

Commit

Permalink
fix: 修复循环拉取任务失效
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlkl committed Jul 13, 2023
1 parent 72be2db commit dae3b3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions analysis-tool-sdk-golang/api/bkrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (c *BkRepoClient) GenerateInputFile() (*os.File, error) {

// updateSubtaskStatus 更新任务状态为执行中
func (c *BkRepoClient) updateSubtaskStatus() error {
url := c.Args.Url + analystTemporaryPrefix + "/scan/subtask/" + c.Args.TaskId + "/status?token=" + c.Args.Token + "&status=EXECUTING"
url := c.Args.Url + analystTemporaryPrefix + "/scan/subtask/" + c.ToolInput.TaskId + "/status?token=" + c.Args.Token + "&status=EXECUTING"
request, err := http.NewRequest("PUT", url, nil)
if err != nil {
return err
Expand All @@ -136,7 +136,7 @@ func (c *BkRepoClient) updateSubtaskStatus() error {
}
defer response.Body.Close()
if response.StatusCode != 200 {
return errors.New("更新扫描任务[" + c.Args.TaskId + "]状态失败, status: " + response.Status)
return errors.New("更新扫描任务[" + c.ToolInput.TaskId + "]状态失败, status: " + response.Status)
}

res := new(Response[bool])
Expand All @@ -145,7 +145,7 @@ func (c *BkRepoClient) updateSubtaskStatus() error {
}

if !res.Data {
return errors.New("更新扫描任务[" + c.Args.TaskId + "]状态失败, msg: " +
return errors.New("更新扫描任务[" + c.ToolInput.TaskId + "]状态失败, msg: " +
res.Message + "code: " + strconv.Itoa(res.Code))
}
return nil
Expand All @@ -165,22 +165,21 @@ func (c *BkRepoClient) initToolInput() error {
c.ToolInput = toolInput
} else if c.Args.TaskId != "" {
var err error
if c.ToolInput, err = c.fetchToolInput(); err != nil {
if c.ToolInput, err = c.fetchToolInput(c.Args.TaskId); err != nil {
return err
}
} else {
var err error
if c.ToolInput, err = c.pullToolInput(); err != nil {
return err
}
c.Args.TaskId = c.ToolInput.TaskId
}
return nil
}

// fetchToolInput 从制品分析服务拉取工具输入
func (c *BkRepoClient) fetchToolInput() (*object.ToolInput, error) {
url := c.Args.Url + analystTemporaryPrefix + "/scan/subtask/" + c.Args.TaskId + "/input?token=" + c.Args.Token
func (c *BkRepoClient) fetchToolInput(taskId string) (*object.ToolInput, error) {
url := c.Args.Url + analystTemporaryPrefix + "/scan/subtask/" + taskId + "/input?token=" + c.Args.Token
return c.doFetchToolInput(url)
}

Expand Down
2 changes: 1 addition & 1 deletion analysis-tool-sdk-golang/object/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ func (arg *Arguments) Online() bool {

// ShouldKeepRunning 是否无限循环拉取任务执行
func (arg *Arguments) ShouldKeepRunning() bool {
return arg.Online() && arg.KeepRunning && arg.ExecutionCluster != ""
return arg.Online() && arg.KeepRunning && arg.TaskId == ""
}

0 comments on commit dae3b3d

Please sign in to comment.