mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
check if state field exists before processing a message
This commit is contained in:
parent
cf8775b39d
commit
03341dbe42
1 changed files with 20 additions and 19 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
ICUUID := payload.Properties.UUID
|
||||
_, err = uuid.Parse(ICUUID)
|
||||
if payload.State != nil {
|
||||
// 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 {
|
||||
return fmt.Errorf("AMQP: UUID not valid: %v, message ignored: %v \n", ICUUID, string(message.Body))
|
||||
if err != nil {
|
||||
return fmt.Errorf("AMQP: UUID not valid: %v, message ignored: %v \n", ICUUID, string(message.Body))
|
||||
}
|
||||
var sToBeUpdated InfrastructureComponent
|
||||
err = sToBeUpdated.ByUUID(ICUUID)
|
||||
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
// create new record
|
||||
err = createNewICviaAMQP(payload)
|
||||
} else if err != nil {
|
||||
// database error
|
||||
err = fmt.Errorf("AMQP: Database error for IC %v DB error message: %v", ICUUID, err)
|
||||
} else {
|
||||
// update record based on payload
|
||||
err = sToBeUpdated.updateICviaAMQP(payload)
|
||||
}
|
||||
}
|
||||
|
||||
var sToBeUpdated InfrastructureComponent
|
||||
err = sToBeUpdated.ByUUID(ICUUID)
|
||||
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
// create new record
|
||||
err = createNewICviaAMQP(payload)
|
||||
} else if err != nil {
|
||||
// database error
|
||||
err = fmt.Errorf("AMQP: Database error for IC %v DB error message: %v", ICUUID, err)
|
||||
} else {
|
||||
// update record based on payload
|
||||
err = sToBeUpdated.updateICviaAMQP(payload)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue