From 6cf08d8131afcb5d29f7b8f0f9159adbf00a4be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Tue, 27 Apr 2021 19:17:43 +0200 Subject: [PATCH] Fix async update --- handlers_nats.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/handlers_nats.go b/handlers_nats.go index f4074c6..b3313b5 100644 --- a/handlers_nats.go +++ b/handlers_nats.go @@ -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 }