feat(cloudcommon): set TaskNotifyUrl in GetTaskRequestHeader

To support cross-service task callbacks, you must set TaskNotifyUrl,
which is automatically added to TaskRequestHeader here
This commit is contained in:
rainzm
2021-04-07 17:01:08 +08:00
parent f8f99365a2
commit f7add55303
2 changed files with 20 additions and 1 deletions
+11
View File
@@ -19,6 +19,7 @@ import (
"database/sql"
"fmt"
"net/http"
"path/filepath"
"reflect"
"runtime/debug"
"strconv"
@@ -826,9 +827,19 @@ func (task *STask) GetTaskRequestHeader() http.Header {
}
header := mcclient.GetTokenHeaders(userCred)
header.Set(mcclient.TASK_ID, task.GetTaskId())
if len(serviceUrl) > 0 {
notifyUrl := filepath.Join(serviceUrl, "tasks", task.GetTaskId())
header.Set(mcclient.TASK_NOTIFY_URL, notifyUrl)
}
return header
}
var serviceUrl string
func SetServiceUrl(url string) {
serviceUrl = url
}
func (task *STask) GetStartTime() time.Time {
return task.CreatedAt
}