mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
AMQP: Modify sendAction method
This commit is contained in:
parent
f55120df52
commit
0fc183a70b
2 changed files with 15 additions and 13 deletions
|
@ -27,7 +27,6 @@ import (
|
|||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RegisterAMQPEndpoint(r *gin.RouterGroup) {
|
||||
|
@ -62,14 +61,14 @@ func sendActionToIC(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
//now := time.Now()
|
||||
|
||||
for _, action := range actions {
|
||||
if action.When == 0 {
|
||||
/*if action.When == 0 {
|
||||
action.When = float32(now.Unix())
|
||||
}
|
||||
|
||||
err = SendActionAMQP(action, s.UUID)
|
||||
}*/
|
||||
*action.UUID = s.UUID
|
||||
err = SendActionAMQP(action)
|
||||
if err != nil {
|
||||
helper.InternalServerError(c, "Unable to send actions to IC: "+err.Error())
|
||||
return
|
||||
|
|
|
@ -46,8 +46,9 @@ type Action struct {
|
|||
Act string `json:"action"`
|
||||
When float32 `json:"when"`
|
||||
Parameters struct{} `json:"parameters"`
|
||||
Model struct{} `json:"model"`
|
||||
Results struct{} `json:"results"`
|
||||
UUID *string `json:"uuid"`
|
||||
//Model struct{} `json:"model"`
|
||||
//Results struct{} `json:"results"`
|
||||
}
|
||||
|
||||
type ICUpdate struct {
|
||||
|
@ -133,7 +134,7 @@ func ConnectAMQP(uri string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func SendActionAMQP(action Action, uuid string) error {
|
||||
func SendActionAMQP(action Action) error {
|
||||
|
||||
payload, err := json.Marshal(action)
|
||||
if err != nil {
|
||||
|
@ -149,11 +150,12 @@ func SendActionAMQP(action Action, uuid string) error {
|
|||
Body: payload,
|
||||
}
|
||||
|
||||
if uuid != "" {
|
||||
msg.Headers["uuid"] = uuid
|
||||
msg.Headers["action"] = "ping"
|
||||
err = CheckConnection()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("AMQP: Sending message", string(msg.Body))
|
||||
err = client.channel.Publish(VILLAS_EXCHANGE,
|
||||
"",
|
||||
false,
|
||||
|
@ -168,8 +170,9 @@ func PingAMQP() error {
|
|||
|
||||
var a Action
|
||||
a.Act = "ping"
|
||||
*a.UUID = ""
|
||||
|
||||
err := SendActionAMQP(a, "")
|
||||
err := SendActionAMQP(a)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue