Fix async update

This commit is contained in:
Adam Štrauch 2021-04-27 19:17:43 +02:00
parent 162daf6cba
commit 6cf08d8131
Signed by: cx
GPG key ID: 018304FFA8988F8D

View file

@ -138,19 +138,19 @@ func createEventHandler(m *nats.Msg, message *RequestMessage) error {
err := json.Unmarshal(body, &appTemplate)
if err != nil {
log.Println("ERROR create application problem: " + err.Error())
publish(appTemplate.Name, "payload parsing problem", true)
publish(message.AppName, "payload parsing problem", true)
return err
}
err = apps.New(appTemplate.Name, appTemplate.SSHPort, appTemplate.HTTPPort, appTemplate.Image, appTemplate.CPU, appTemplate.Memory)
err = apps.New(message.AppName, appTemplate.SSHPort, appTemplate.HTTPPort, appTemplate.Image, appTemplate.CPU, appTemplate.Memory)
if err != nil {
if validationError, ok := err.(apps.ValidationError); ok {
log.Println("ERROR create application problem: " + validationError.Error())
publish(appTemplate.Name, "validation problem", true)
publish(message.AppName, "validation problem", true)
return err
}
log.Println("ERROR create application problem: " + err.Error())
publish(appTemplate.Name, "backend problem", true)
publish(message.AppName, "backend problem", true)
return err
}
@ -161,31 +161,30 @@ func createEventHandler(m *nats.Msg, message *RequestMessage) error {
err = container.Create()
if err != nil {
log.Println("ERROR create application problem: " + err.Error())
publish(appTemplate.Name, "backend problem", true)
publish(message.AppName, "backend problem", true)
return err
}
err = container.Start()
if err != nil {
log.Println("ERROR create application problem: " + err.Error())
publish(appTemplate.Name, "backend problem", true)
publish(message.AppName, "backend problem", true)
return err
}
publish(appTemplate.Name, "created", false)
publish(message.AppName, "created", false)
return nil
}
// Update existing app
func updateEventHandler(m *nats.Msg, message *RequestMessage) error {
appTemplate := apps.App{}
body := []byte(message.Payload)
err := json.Unmarshal(body, &appTemplate)
if err != nil {
log.Println("ERROR update application problem: " + err.Error())
publish(appTemplate.Name, "payload parsing problem", true)
publish(message.AppName, "payload parsing problem", true)
return err
}
@ -193,11 +192,11 @@ func updateEventHandler(m *nats.Msg, message *RequestMessage) error {
if err != nil {
if validationError, ok := err.(apps.ValidationError); ok {
log.Println("ERROR update application problem: " + validationError.Error())
publish(appTemplate.Name, "backend problem", true)
publish(message.AppName, "backend problem", true)
return err
}
log.Println("ERROR update application problem: " + err.Error())
publish(appTemplate.Name, "backend problem", true)
publish(message.AppName, "backend problem", true)
return err
}
@ -212,25 +211,25 @@ func updateEventHandler(m *nats.Msg, message *RequestMessage) error {
}
if err != nil {
log.Println("ERROR update application problem: " + err.Error())
publish(appTemplate.Name, "backend problem", true)
publish(app.Name, "backend problem", true)
return err
}
err = container.Create()
if err != nil {
log.Println("ERROR update application problem: " + err.Error())
publish(appTemplate.Name, "backend problem", true)
publish(app.Name, "backend problem", true)
return err
}
err = container.Start()
if err != nil {
log.Println("ERROR update application problem: " + err.Error())
publish(appTemplate.Name, "backend problem", true)
publish(app.Name, "backend problem", true)
return err
}
publish(appTemplate.Name, "updated", false)
publish(app.Name, "updated", false)
return nil
}