Browse Source

提交代码

tags/v1.22.4.1^2
ychao_1983 3 years ago
parent
commit
484716c9b6
1 changed files with 33 additions and 4 deletions
  1. +33
    -4
      modules/cloudbrain/resty.go

+ 33
- 4
modules/cloudbrain/resty.go View File

@@ -30,6 +30,7 @@ const (
Custom = "custom"
LogPageSize = 500
LogPageTokenExpired = "5m"
pageSize = 15
)

func getRestyClient() *resty.Client {
@@ -218,6 +219,8 @@ func CommitImage(jobID string, params models.CommitImageParams) error {
if err != nil && !models.IsErrImageNotExist(err) {
return fmt.Errorf("resty CommitImage: %v", err)
}
var createTime time.Time
var isSetCreatedUnix = false
if dbImage != nil {
if dbImage.UID != params.UID {
return models.ErrorImageTagExist{
@@ -229,6 +232,19 @@ func CommitImage(jobID string, params models.CommitImageParams) error {
Tag: params.ImageTag,
}

} else { //覆盖提交

result, err := GetImagesPageable(1, pageSize, Custom, "")
if err == nil && result.Code == "S000" {
for _, v := range result.Payload.ImageInfo {
if v.Place == dbImage.Place {
isSetCreatedUnix = true
createTime, _ = time.Parse(time.RFC3339, v.Createtime)
break
}
}
}

}
}
}
@@ -277,6 +293,7 @@ sendjob:
dbImage.IsPrivate = params.IsPrivate
dbImage.Description = params.ImageDescription
dbImage.Status = models.IMAGE_STATUS_COMMIT
image = *dbImage
if err := models.UpdateLocalImage(dbImage); err != nil {
log.Error("Failed to update image record.", err)
return fmt.Errorf("CommitImage err: %s", res.String())
@@ -295,22 +312,26 @@ sendjob:
return nil
})
if err == nil {
go updateImageStatus(image)

go updateImageStatus(image, isSetCreatedUnix, createTime)
}
return err
}

func updateImageStatus(image models.Image) {
func updateImageStatus(image models.Image, isSetCreatedUnix bool, createTime time.Time) {
attemps := 5
commitSuccess := false
time.Sleep(5 * time.Second)
for i := 0; i < attemps; i++ {
pageSize := 15

if commitSuccess {
break
}

result, err := GetImagesPageable(1, pageSize, Custom, "")
if err == nil && result.Code == "S000" {
for _, v := range result.Payload.ImageInfo {
if v.Place == image.Place {
if v.Place == image.Place && (!isSetCreatedUnix || (isSetCreatedUnix && createTimeUpdated(v, createTime))) {
image.Status = models.IMAGE_STATUS_SUCCESS
models.UpdateLocalImageStatus(&image)
commitSuccess = true
@@ -333,6 +354,14 @@ func updateImageStatus(image models.Image) {

}

func createTimeUpdated(v *models.ImageInfo, createTime time.Time) bool {
newTime, err := time.Parse(time.RFC3339, v.Createtime)
if err != nil {
return false
}
return newTime.After(createTime)
}

func StopJob(jobID string) error {
checkSetting()
client := getRestyClient()


Loading…
Cancel
Save