[REV] optimize event ,in one event,but multi action,allow pass throth

This commit is contained in:
bay1ts 2017-11-23 09:57:25 +08:00
parent 87a5d1cb5f
commit 69ef555716
4 changed files with 54 additions and 16 deletions

View File

@ -402,6 +402,7 @@ class RepoBuilder():
return True
def feedback(self):
time.sleep(2)
body = {
"deploy_version": self.deploy_version,
"event_id": self.event_id
@ -446,7 +447,7 @@ class RepoBuilder():
success = build_func()
if success:
# self.log.info("构建完成。", step="build-worker")
self.log.info("构建完成。", step="callback",status="success")
self.log.info("构建完成。", step="build-worker",status="success")
ok = self.feedback()
if not ok:

View File

@ -79,7 +79,7 @@ func createEvent(eventID, serviceID, optType, tenantID, deployVersion string) (*
event.DeployVersion = version
event.OldDeployVersion = oldDeployVersion
status, err := checkCanAddEvent(serviceID)
status, err := checkCanAddEvent(serviceID,event.EventID)
if err != nil {
logrus.Errorf("error check event")
return nil, status, nil
@ -119,8 +119,9 @@ func autoTimeOut(event *dbmodel.ServiceEvent) {
}
}
}
func checkCanAddEvent(s string) (int, error) {
func checkCanAddEvent(s ,eventID string) (int, error) {
events, err := db.GetManager().ServiceEventDao().GetEventByServiceID(s)
if err != nil {
return 3, err
}
@ -131,6 +132,9 @@ func checkCanAddEvent(s string) (int, error) {
return 0, nil
}
latestEvent := events[0]
if latestEvent.EventID==eventID {
return 0,nil
}
if latestEvent.FinalStatus == "" {
//未完成
timeOut, err := checkEventTimeOut(latestEvent)
@ -514,6 +518,7 @@ func (t *TenantStruct) BuildService(w http.ResponseWriter, r *http.Request) {
version.DeliveredType=build.Body.Kind
version.CodeVersion=""
version.BuildVersion=build.Body.DeployVersion
db.GetManager().VersionInfoDao().AddModel(&version)
//save
//version.DeliveredPath
//version.FinalStatus

View File

@ -26,6 +26,8 @@ import (
"github.com/goodrain/rainbond/pkg/db/config"
"github.com/goodrain/rainbond/pkg/event"
"github.com/goodrain/rainbond/pkg/mq/api/grpc/pb"
"github.com/goodrain/rainbond/pkg/db"
"github.com/goodrain/rainbond/pkg/db/model"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/client"
@ -92,10 +94,12 @@ const pluginDockerfile = "plugins/plugin_dockerfile.pyc"
func (e *exectorManager) appImage(in []byte) {
eventID := gjson.GetBytes(in, "event_id").String()
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
v.FinalStatus="success"
logger := event.GetManager().GetLogger(eventID)
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
w := NewWorker(appImage, "", nil, in)
go func() {
go func(v *model.VersionInfo) {
logrus.Info("start exec app image worker")
defer event.GetManager().ReleaseLogger(logger)
for i := 0; i < 3; i++ {
@ -106,19 +110,25 @@ func (e *exectorManager) appImage(in []byte) {
logger.Info("应用镜像构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
} else {
logger.Info("应用镜像构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
v.FinalStatus="failure"
db.GetManager().VersionInfoDao().UpdateModel(v)
}
} else {
break
}
}
}()
}(v)
db.GetManager().VersionInfoDao().UpdateModel(v)
}
func (e *exectorManager) appSlug(in []byte) {
eventID := gjson.GetBytes(in, "event_id").String()
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
v.FinalStatus="success"
logger := event.GetManager().GetLogger(eventID)
logger.Info("应用代码包构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
w := NewWorker(appSlug, "", nil, in)
go func() {
go func(v *model.VersionInfo) {
logrus.Info("start exec app slug worker")
defer event.GetManager().ReleaseLogger(logger)
for i := 0; i < 3; i++ {
@ -129,40 +139,51 @@ func (e *exectorManager) appSlug(in []byte) {
logger.Info("应用代码包构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
} else {
logger.Info("应用代码包构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
v.FinalStatus="failure"
db.GetManager().VersionInfoDao().UpdateModel(v)
}
} else {
break
}
}
}()
}(v)
db.GetManager().VersionInfoDao().UpdateModel(v)
}
func (e *exectorManager) imageManual(in []byte) {
eventID := gjson.GetBytes(in, "event_id").String()
logger := event.GetManager().GetLogger(eventID)
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
v.FinalStatus="success"
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
w := NewWorker(imageManual, "", nil, in)
go func() {
go func(v *model.VersionInfo) {
defer event.GetManager().ReleaseLogger(logger)
logrus.Info("start exec image manual worker")
for i := 0; i < 3; i++ {
c, err := w.run(time.Minute * 30)
fmt.Printf("out put is ------------%s",string(c))
_, err := w.run(time.Minute * 30)
if err != nil {
logrus.Errorf("exec image manual python shell error:%s", err.Error())
if i < 3 {
logger.Info("应用镜像构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
} else {
logger.Info("应用镜像构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
v.FinalStatus="failure"
db.GetManager().VersionInfoDao().UpdateModel(v)
}
} else {
break
}
}
}()
}(v)
db.GetManager().VersionInfoDao().UpdateModel(v)
}
func (e *exectorManager) codeCheck(in []byte) {
eventID := gjson.GetBytes(in, "event_id").String()
logger := event.GetManager().GetLogger(eventID)
logger.Info("应用代码检测任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
w := NewWorker(codeCheck, "", nil, in)
go func() {
@ -185,11 +206,15 @@ func (e *exectorManager) codeCheck(in []byte) {
}
func (e *exectorManager) appBuild(in []byte) {
eventID := gjson.GetBytes(in, "event_id").String()
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
v.FinalStatus="success"
logger := event.GetManager().GetLogger(eventID)
logger.Info("应用编译构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
w := NewWorker(appBuild, "", nil, in)
go func() {
go func(v *model.VersionInfo) {
logrus.Info("start exec build app worker")
defer event.GetManager().ReleaseLogger(logger)
for i := 0; i < 3; i++ {
@ -204,10 +229,13 @@ func (e *exectorManager) appBuild(in []byte) {
} else {
logrus.Infof("build task success,eventID is %s",eventID)
//logger.Info("应用编译构建任务执行成功", map[string]string{"step": "callback", "status": "success"})
v.FinalStatus="failure"
db.GetManager().VersionInfoDao().UpdateModel(v)
break
}
}
}()
}(v)
db.GetManager().VersionInfoDao().UpdateModel(v)
}
func (e *exectorManager) pluginImageBuild1(in []byte) {

View File

@ -29,14 +29,14 @@ import (
//AddModel AddModel
func (c *VersionInfoDaoImpl) AddModel(mo model.Interface) error {
result := mo.(*model.ServiceEvent)
var oldResult model.ServiceEvent
result := mo.(*model.VersionInfo)
var oldResult model.VersionInfo
if ok := c.DB.Where("event_id=?", result.EventID).Find(&oldResult).RecordNotFound(); ok {
if err := c.DB.Create(result).Error; err != nil {
return err
}
} else {
fmt.Errorf("event result is exist")
fmt.Errorf("version is exist")
return nil
}
return nil
@ -45,6 +45,10 @@ func (c *VersionInfoDaoImpl) AddModel(mo model.Interface) error {
//UpdateModel UpdateModel
func (c *VersionInfoDaoImpl) UpdateModel(mo model.Interface) error {
result := mo.(*model.VersionInfo)
if err := c.DB.Save(result).Error; err != nil {
return err
}
return nil
}