perf: Optimize container task log output (#11393)

This commit is contained in:
ssongliu 2025-12-19 11:39:40 +08:00 committed by GitHub
parent 2b81f7ef7a
commit 8642e20d19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 32 deletions

View file

@ -212,7 +212,7 @@ func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string
}
if status == "Pull complete" || status == "Download complete" {
id, _ := progress["id"].(string)
progressStr := fmt.Sprintf("%s [%s] --- %.2f%%", status, id, 100.0)
progressStr := fmt.Sprintf("%s %s", status, id)
_ = setLog(id, progressStr, task)
}
}
@ -246,7 +246,7 @@ func (c Client) PushImageWithProcessAndOptions(task *task.Task, imageName string
logProcess(progress, task)
case "Pushed":
id, _ := progress["id"].(string)
progressStr := fmt.Sprintf("%s [%s] --- %.2f%%", status, id, 100.0)
progressStr := fmt.Sprintf("%s %s", status, id)
_ = setLog(id, progressStr, task)
default:
progressStr, _ := json.Marshal(progress)
@ -290,7 +290,7 @@ func (c Client) BuildImageWithProcessAndOptions(task *task.Task, tar io.ReadClos
logProcess(progress, task)
case "Pull complete", "Download complete", "Verifying Checksum":
id, _ := progress["id"].(string)
progressStr := fmt.Sprintf("%s [%s] --- %.2f%%", status, id, 100.0)
progressStr := fmt.Sprintf("%s %s", status, id)
_ = setLog(id, progressStr, task)
default:
progressStr, _ := json.Marshal(progress)
@ -304,38 +304,12 @@ func (c Client) PullImageWithProcess(task *task.Task, imageName string) error {
return c.PullImageWithProcessAndOptions(task, imageName, image.PullOptions{})
}
func formatBytes(bytes uint64) string {
const (
KB = 1024
MB = 1024 * KB
GB = 1024 * MB
TB = 1024 * GB
)
switch {
case bytes < MB:
return fmt.Sprintf("%.0fKB", float64(bytes)/KB)
case bytes < GB:
return fmt.Sprintf("%.1fMB", float64(bytes)/MB)
case bytes < TB:
return fmt.Sprintf("%.1fGB", float64(bytes)/GB)
default:
return fmt.Sprintf("%.2fTB", float64(bytes)/TB)
}
}
func logProcess(progress map[string]interface{}, task *task.Task) {
status, _ := progress["status"].(string)
id, _ := progress["id"].(string)
progressDetail, _ := progress["progressDetail"].(map[string]interface{})
current, _ := progressDetail["current"].(float64)
progressItem, _ := progress["progress"].(string)
progressStr := ""
total, ok := progressDetail["total"].(float64)
if ok {
progressStr = fmt.Sprintf("%s [%s] --- %.2f%%", status, id, (current/total)*100)
} else {
progressStr = fmt.Sprintf("%s [%s] --- %s ", status, id, formatBytes(uint64(current)))
}
progressStr = fmt.Sprintf("%s %s %s", status, id, progressItem)
_ = setLog(id, progressStr, task)
}

View file

@ -80,7 +80,7 @@ const formRef = ref<FormInstance>();
const handleChange = () => {
let repoURL = loadDetailInfo(form.repoID);
form.name = form.tagName.indexOf(repoURL) !== -1 ? form.tagName.replaceAll(repoURL, '') : form.tagName;
form.name = form.tagName.indexOf(repoURL) !== -1 ? form.tagName.replaceAll(repoURL + '/', '') : form.tagName;
};
const onSubmit = async (formEl: FormInstance | undefined) => {