mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 11:47:36 +08:00
[REV] optimize event ,in one event,but multi action,allow pass throth
This commit is contained in:
parent
87a5d1cb5f
commit
69ef555716
@ -402,6 +402,7 @@ class RepoBuilder():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def feedback(self):
|
def feedback(self):
|
||||||
|
time.sleep(2)
|
||||||
body = {
|
body = {
|
||||||
"deploy_version": self.deploy_version,
|
"deploy_version": self.deploy_version,
|
||||||
"event_id": self.event_id
|
"event_id": self.event_id
|
||||||
@ -446,7 +447,7 @@ class RepoBuilder():
|
|||||||
success = build_func()
|
success = build_func()
|
||||||
if success:
|
if success:
|
||||||
# self.log.info("构建完成。", step="build-worker")
|
# self.log.info("构建完成。", step="build-worker")
|
||||||
self.log.info("构建完成。", step="callback",status="success")
|
self.log.info("构建完成。", step="build-worker",status="success")
|
||||||
|
|
||||||
ok = self.feedback()
|
ok = self.feedback()
|
||||||
if not ok:
|
if not ok:
|
||||||
|
@ -79,7 +79,7 @@ func createEvent(eventID, serviceID, optType, tenantID, deployVersion string) (*
|
|||||||
event.DeployVersion = version
|
event.DeployVersion = version
|
||||||
event.OldDeployVersion = oldDeployVersion
|
event.OldDeployVersion = oldDeployVersion
|
||||||
|
|
||||||
status, err := checkCanAddEvent(serviceID)
|
status, err := checkCanAddEvent(serviceID,event.EventID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error check event")
|
logrus.Errorf("error check event")
|
||||||
return nil, status, nil
|
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)
|
events, err := db.GetManager().ServiceEventDao().GetEventByServiceID(s)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 3, err
|
return 3, err
|
||||||
}
|
}
|
||||||
@ -131,6 +132,9 @@ func checkCanAddEvent(s string) (int, error) {
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
latestEvent := events[0]
|
latestEvent := events[0]
|
||||||
|
if latestEvent.EventID==eventID {
|
||||||
|
return 0,nil
|
||||||
|
}
|
||||||
if latestEvent.FinalStatus == "" {
|
if latestEvent.FinalStatus == "" {
|
||||||
//未完成
|
//未完成
|
||||||
timeOut, err := checkEventTimeOut(latestEvent)
|
timeOut, err := checkEventTimeOut(latestEvent)
|
||||||
@ -514,6 +518,7 @@ func (t *TenantStruct) BuildService(w http.ResponseWriter, r *http.Request) {
|
|||||||
version.DeliveredType=build.Body.Kind
|
version.DeliveredType=build.Body.Kind
|
||||||
version.CodeVersion=""
|
version.CodeVersion=""
|
||||||
version.BuildVersion=build.Body.DeployVersion
|
version.BuildVersion=build.Body.DeployVersion
|
||||||
|
db.GetManager().VersionInfoDao().AddModel(&version)
|
||||||
//save
|
//save
|
||||||
//version.DeliveredPath
|
//version.DeliveredPath
|
||||||
//version.FinalStatus
|
//version.FinalStatus
|
||||||
|
@ -26,6 +26,8 @@ import (
|
|||||||
"github.com/goodrain/rainbond/pkg/db/config"
|
"github.com/goodrain/rainbond/pkg/db/config"
|
||||||
"github.com/goodrain/rainbond/pkg/event"
|
"github.com/goodrain/rainbond/pkg/event"
|
||||||
"github.com/goodrain/rainbond/pkg/mq/api/grpc/pb"
|
"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/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
@ -92,10 +94,12 @@ const pluginDockerfile = "plugins/plugin_dockerfile.pyc"
|
|||||||
|
|
||||||
func (e *exectorManager) appImage(in []byte) {
|
func (e *exectorManager) appImage(in []byte) {
|
||||||
eventID := gjson.GetBytes(in, "event_id").String()
|
eventID := gjson.GetBytes(in, "event_id").String()
|
||||||
|
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
|
||||||
|
v.FinalStatus="success"
|
||||||
logger := event.GetManager().GetLogger(eventID)
|
logger := event.GetManager().GetLogger(eventID)
|
||||||
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||||
w := NewWorker(appImage, "", nil, in)
|
w := NewWorker(appImage, "", nil, in)
|
||||||
go func() {
|
go func(v *model.VersionInfo) {
|
||||||
logrus.Info("start exec app image worker")
|
logrus.Info("start exec app image worker")
|
||||||
defer event.GetManager().ReleaseLogger(logger)
|
defer event.GetManager().ReleaseLogger(logger)
|
||||||
for i := 0; i < 3; i++ {
|
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"})
|
logger.Info("应用镜像构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
|
||||||
} else {
|
} else {
|
||||||
logger.Info("应用镜像构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
logger.Info("应用镜像构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
||||||
|
v.FinalStatus="failure"
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}(v)
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
}
|
}
|
||||||
func (e *exectorManager) appSlug(in []byte) {
|
func (e *exectorManager) appSlug(in []byte) {
|
||||||
eventID := gjson.GetBytes(in, "event_id").String()
|
eventID := gjson.GetBytes(in, "event_id").String()
|
||||||
|
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
|
||||||
|
v.FinalStatus="success"
|
||||||
|
|
||||||
logger := event.GetManager().GetLogger(eventID)
|
logger := event.GetManager().GetLogger(eventID)
|
||||||
logger.Info("应用代码包构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
logger.Info("应用代码包构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||||
w := NewWorker(appSlug, "", nil, in)
|
w := NewWorker(appSlug, "", nil, in)
|
||||||
go func() {
|
go func(v *model.VersionInfo) {
|
||||||
logrus.Info("start exec app slug worker")
|
logrus.Info("start exec app slug worker")
|
||||||
defer event.GetManager().ReleaseLogger(logger)
|
defer event.GetManager().ReleaseLogger(logger)
|
||||||
for i := 0; i < 3; i++ {
|
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"})
|
logger.Info("应用代码包构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
|
||||||
} else {
|
} else {
|
||||||
logger.Info("应用代码包构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
logger.Info("应用代码包构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
||||||
|
v.FinalStatus="failure"
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}(v)
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
}
|
}
|
||||||
func (e *exectorManager) imageManual(in []byte) {
|
func (e *exectorManager) imageManual(in []byte) {
|
||||||
eventID := gjson.GetBytes(in, "event_id").String()
|
eventID := gjson.GetBytes(in, "event_id").String()
|
||||||
logger := event.GetManager().GetLogger(eventID)
|
logger := event.GetManager().GetLogger(eventID)
|
||||||
|
|
||||||
|
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
|
||||||
|
v.FinalStatus="success"
|
||||||
|
|
||||||
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||||
w := NewWorker(imageManual, "", nil, in)
|
w := NewWorker(imageManual, "", nil, in)
|
||||||
go func() {
|
go func(v *model.VersionInfo) {
|
||||||
defer event.GetManager().ReleaseLogger(logger)
|
defer event.GetManager().ReleaseLogger(logger)
|
||||||
logrus.Info("start exec image manual worker")
|
logrus.Info("start exec image manual worker")
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
c, err := w.run(time.Minute * 30)
|
_, err := w.run(time.Minute * 30)
|
||||||
fmt.Printf("out put is ------------%s",string(c))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("exec image manual python shell error:%s", err.Error())
|
logrus.Errorf("exec image manual python shell error:%s", err.Error())
|
||||||
if i < 3 {
|
if i < 3 {
|
||||||
logger.Info("应用镜像构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
|
logger.Info("应用镜像构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
|
||||||
} else {
|
} else {
|
||||||
logger.Info("应用镜像构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
logger.Info("应用镜像构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
||||||
|
v.FinalStatus="failure"
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}(v)
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
}
|
}
|
||||||
func (e *exectorManager) codeCheck(in []byte) {
|
func (e *exectorManager) codeCheck(in []byte) {
|
||||||
eventID := gjson.GetBytes(in, "event_id").String()
|
eventID := gjson.GetBytes(in, "event_id").String()
|
||||||
logger := event.GetManager().GetLogger(eventID)
|
logger := event.GetManager().GetLogger(eventID)
|
||||||
|
|
||||||
|
|
||||||
logger.Info("应用代码检测任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
logger.Info("应用代码检测任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||||
w := NewWorker(codeCheck, "", nil, in)
|
w := NewWorker(codeCheck, "", nil, in)
|
||||||
go func() {
|
go func() {
|
||||||
@ -185,11 +206,15 @@ func (e *exectorManager) codeCheck(in []byte) {
|
|||||||
}
|
}
|
||||||
func (e *exectorManager) appBuild(in []byte) {
|
func (e *exectorManager) appBuild(in []byte) {
|
||||||
eventID := gjson.GetBytes(in, "event_id").String()
|
eventID := gjson.GetBytes(in, "event_id").String()
|
||||||
|
|
||||||
|
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
|
||||||
|
v.FinalStatus="success"
|
||||||
|
|
||||||
logger := event.GetManager().GetLogger(eventID)
|
logger := event.GetManager().GetLogger(eventID)
|
||||||
logger.Info("应用编译构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
logger.Info("应用编译构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||||
|
|
||||||
w := NewWorker(appBuild, "", nil, in)
|
w := NewWorker(appBuild, "", nil, in)
|
||||||
go func() {
|
go func(v *model.VersionInfo) {
|
||||||
logrus.Info("start exec build app worker")
|
logrus.Info("start exec build app worker")
|
||||||
defer event.GetManager().ReleaseLogger(logger)
|
defer event.GetManager().ReleaseLogger(logger)
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
@ -204,10 +229,13 @@ func (e *exectorManager) appBuild(in []byte) {
|
|||||||
} else {
|
} else {
|
||||||
logrus.Infof("build task success,eventID is %s",eventID)
|
logrus.Infof("build task success,eventID is %s",eventID)
|
||||||
//logger.Info("应用编译构建任务执行成功", map[string]string{"step": "callback", "status": "success"})
|
//logger.Info("应用编译构建任务执行成功", map[string]string{"step": "callback", "status": "success"})
|
||||||
|
v.FinalStatus="failure"
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}(v)
|
||||||
|
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *exectorManager) pluginImageBuild1(in []byte) {
|
func (e *exectorManager) pluginImageBuild1(in []byte) {
|
||||||
|
@ -29,14 +29,14 @@ import (
|
|||||||
|
|
||||||
//AddModel AddModel
|
//AddModel AddModel
|
||||||
func (c *VersionInfoDaoImpl) AddModel(mo model.Interface) error {
|
func (c *VersionInfoDaoImpl) AddModel(mo model.Interface) error {
|
||||||
result := mo.(*model.ServiceEvent)
|
result := mo.(*model.VersionInfo)
|
||||||
var oldResult model.ServiceEvent
|
var oldResult model.VersionInfo
|
||||||
if ok := c.DB.Where("event_id=?", result.EventID).Find(&oldResult).RecordNotFound(); ok {
|
if ok := c.DB.Where("event_id=?", result.EventID).Find(&oldResult).RecordNotFound(); ok {
|
||||||
if err := c.DB.Create(result).Error; err != nil {
|
if err := c.DB.Create(result).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Errorf("event result is exist")
|
fmt.Errorf("version is exist")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -45,6 +45,10 @@ func (c *VersionInfoDaoImpl) AddModel(mo model.Interface) error {
|
|||||||
|
|
||||||
//UpdateModel UpdateModel
|
//UpdateModel UpdateModel
|
||||||
func (c *VersionInfoDaoImpl) UpdateModel(mo model.Interface) error {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user