Commit 03341dbe authored by Sonja Happ's avatar Sonja Happ
Browse files

check if state field exists before processing a message

parent cf8775b3
...@@ -261,26 +261,27 @@ func processMessage(message amqp.Delivery) error { ...@@ -261,26 +261,27 @@ func processMessage(message amqp.Delivery) error {
return fmt.Errorf("AMQP: Could not unmarshal message to JSON: %v err: %v", string(message.Body), err) return fmt.Errorf("AMQP: Could not unmarshal message to JSON: %v err: %v", string(message.Body), err)
} }
ICUUID := payload.Properties.UUID if payload.State != nil {
_, err = uuid.Parse(ICUUID) // if a message contains a "state" field, it is an update for an IC
ICUUID := payload.Properties.UUID
_, err = uuid.Parse(ICUUID)
if err != nil { if err != nil {
return fmt.Errorf("AMQP: UUID not valid: %v, message ignored: %v \n", ICUUID, string(message.Body)) return fmt.Errorf("AMQP: UUID not valid: %v, message ignored: %v \n", ICUUID, string(message.Body))
} }
var sToBeUpdated InfrastructureComponent
var sToBeUpdated InfrastructureComponent err = sToBeUpdated.ByUUID(ICUUID)
err = sToBeUpdated.ByUUID(ICUUID)
if err == gorm.ErrRecordNotFound {
if err == gorm.ErrRecordNotFound { // create new record
// create new record err = createNewICviaAMQP(payload)
err = createNewICviaAMQP(payload) } else if err != nil {
} else if err != nil { // database error
// database error err = fmt.Errorf("AMQP: Database error for IC %v DB error message: %v", ICUUID, err)
err = fmt.Errorf("AMQP: Database error for IC %v DB error message: %v", ICUUID, err) } else {
} else { // update record based on payload
// update record based on payload err = sToBeUpdated.updateICviaAMQP(payload)
err = sToBeUpdated.updateICviaAMQP(payload) }
} }
return err return err
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment