[ADD] start and finish time for build version

This commit is contained in:
GLYASAI 2019-08-16 06:53:16 +08:00
parent 3b03407139
commit b89b176c4e
5 changed files with 24 additions and 28 deletions

View File

@ -20,9 +20,9 @@ package handler
import (
"fmt"
"time"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/db"
dbmodel "github.com/goodrain/rainbond/db/model"
@ -86,6 +86,7 @@ func (o *OperationHandler) Build(buildInfo model.BuildInfoRequestStruct) (re Ope
BuildVersion: buildInfo.DeployVersion,
Cmd: buildInfo.ImageInfo.Cmd,
Author: buildInfo.Operator,
FinishTime: time.Now(),
}
serviceID := buildInfo.ServiceID
err = db.GetManager().VersionInfoDao().AddModel(&version)

View File

@ -22,19 +22,14 @@ import (
"fmt"
"time"
"github.com/goodrain/rainbond/builder"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/event"
"github.com/tidwall/gjson"
//"github.com/docker/docker/api/types"
//"github.com/docker/docker/client"
"github.com/docker/docker/client"
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/event"
"github.com/tidwall/gjson" //"github.com/docker/docker/api/types"
//"github.com/docker/docker/client"
)
//ImageBuildItem ImageBuildItem
@ -122,6 +117,7 @@ func (i *ImageBuildItem) StorageVersionInfo(imageURL string) error {
version.ImageName = imageURL
version.RepoURL = i.Image
version.FinalStatus = "success"
version.FinishTime = time.Now()
if err := db.GetManager().VersionInfoDao().UpdateModel(version); err != nil {
return err
}
@ -136,6 +132,7 @@ func (i *ImageBuildItem) UpdateVersionInfo(status string) error {
}
version.FinalStatus = status
version.RepoURL = i.Image
version.FinishTime = time.Now()
if err := db.GetManager().VersionInfoDao().UpdateModel(version); err != nil {
return err
}

View File

@ -25,25 +25,20 @@ import (
"strings"
"time"
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/util"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/client"
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/builder/build"
"github.com/goodrain/rainbond/builder/parser"
"github.com/goodrain/rainbond/builder/parser/code"
"github.com/goodrain/rainbond/event"
"github.com/pquerna/ffjson/ffjson"
"github.com/tidwall/gjson"
//"github.com/docker/docker/api/types"
//"github.com/docker/docker/client"
"github.com/docker/docker/client"
"github.com/goodrain/rainbond/builder/build"
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/db"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/util"
"github.com/pquerna/ffjson/ffjson"
"github.com/tidwall/gjson" //"github.com/docker/docker/api/types"
//"github.com/docker/docker/client"
)
//SourceCodeBuildItem SouceCodeBuildItem
@ -120,7 +115,6 @@ func NewSouceCodeBuildItem(in []byte) *SourceCodeBuildItem {
//Run Run
func (i *SourceCodeBuildItem) Run(timeout time.Duration) error {
//TODO:
// 1.clone
// 2.check dockerfile/ source_code
// 3.build
@ -309,6 +303,7 @@ func (i *SourceCodeBuildItem) UpdateBuildVersionInfo(res *build.Response) error
CodeVersion: i.commit.Hash,
CommitMsg: i.commit.Message,
Author: i.commit.Author,
FinishTime: time.Now(), // TODO(huangrh 20190816): do it in dao
}
if err := i.UpdateVersionInfo(vi); err != nil {
logrus.Errorf("update version info error: %s", err.Error())

View File

@ -27,7 +27,6 @@ import (
"time"
"github.com/Sirupsen/logrus"
"github.com/coreos/etcd/clientv3"
"github.com/docker/docker/client"
"github.com/goodrain/rainbond/cmd/builder/option"
@ -303,9 +302,11 @@ func (e *exectorManager) buildFromSourceCode(task *pb.TaskMessage) {
CodeVersion: i.commit.Hash,
CommitMsg: i.commit.Message,
Author: i.commit.Author,
FinishTime: time.Now(),
}
if err := i.UpdateVersionInfo(vi); err != nil {
logrus.Debugf("update version Info error: %s", err.Error())
logrus.Errorf("update version Info error: %s", err.Error())
// TODO(huangrh 20190816): use logger
}
} else {
var configs = make(map[string]string, len(i.Configs))
@ -387,7 +388,7 @@ func (e *exectorManager) sendAction(tenantID, serviceID, eventID, newVersion, ac
}
if err := e.mqClient.SendBuilderTopic(mqclient.TaskStruct{
Topic: mqclient.WorkerTopic,
TaskType: "rolling_upgrade",
TaskType: "rolling_upgrade", // TODO(huangrh 20190816): Separate from build
TaskBody: body,
}); err != nil {
return err

View File

@ -20,6 +20,7 @@ package model
import (
"fmt"
"time"
"github.com/Sirupsen/logrus"
"github.com/docker/distribution/reference"
@ -47,7 +48,8 @@ type VersionInfo struct {
//success: version available
//failure: build failure
//lost: there is no delivered
FinalStatus string `gorm:"column:final_status;size:40"`
FinalStatus string `gorm:"column:final_status;size:40"`
FinishTime time.Time `gorm:"column:finish_time;"`
}
//TableName 表名