Skip to content

Commit

Permalink
add 'Since' to connection state
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoRoessner committed Feb 15, 2024
1 parent 399a0b3 commit 901ed32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/controller/connectionstate.go
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"github.com/SENERGY-Platform/connection-log-worker/lib/model"
"gopkg.in/mgo.v2/bson"
"time"
)

func (this *Controller) setHubState(gatewayLog model.HubLog) (update bool, err error) {
Expand All @@ -30,7 +31,7 @@ func (this *Controller) setHubState(gatewayLog model.HubLog) (update bool, err e
}
update = count == 0
if update {
_, err = collection.Upsert(bson.M{"gateway": gatewayLog.Id}, HubState{Gateway: gatewayLog.Id, Online: gatewayLog.Connected})
_, err = collection.Upsert(bson.M{"gateway": gatewayLog.Id}, HubState{Gateway: gatewayLog.Id, Online: gatewayLog.Connected, Since: time.Now().Unix()})
}
return
}
Expand All @@ -44,7 +45,7 @@ func (this *Controller) setDeviceState(deviceLog model.DeviceLog) (update bool,
}
update = count == 0
if update {
_, err = collection.Upsert(bson.M{"device": deviceLog.Id}, DeviceState{Device: deviceLog.Id, Online: deviceLog.Connected})
_, err = collection.Upsert(bson.M{"device": deviceLog.Id}, DeviceState{Device: deviceLog.Id, Online: deviceLog.Connected, Since: time.Now().Unix()})
}
return
}
Expand Down
2 changes: 2 additions & 0 deletions lib/controller/mongodb.go
Expand Up @@ -57,9 +57,11 @@ func (this *Controller) getHubStateCollection() (session *mgo.Session, collectio
type DeviceState struct {
Device string `json:"device,omitempty" bson:"device,omitempty"`
Online bool `json:"online" bson:"online"`
Since int64 `json:"since" bson:"since"`
}

type HubState struct {
Gateway string `json:"gateway,omitempty" bson:"gateway,omitempty"`
Online bool `json:"online" bson:"online"`
Since int64 `json:"since" bson:"since"`
}

0 comments on commit 901ed32

Please sign in to comment.