From 00eddc306616eb9795792172dd285afd3c9b8376 Mon Sep 17 00:00:00 2001 From: walkerning Date: Mon, 25 Apr 2016 19:05:04 +0800 Subject: [PATCH] feature(manager): add LastOnline feild to worker struct --- internal/msg.go | 3 ++- manager/server.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/msg.go b/internal/msg.go index 01647c1..b1478f2 100644 --- a/internal/msg.go +++ b/internal/msg.go @@ -18,7 +18,8 @@ type StatusUpdateMsg struct { // A WorkerInfoMsg is the information struct that describe // a worker, and sent from the manager to clients. type WorkerInfoMsg struct { - ID string `json:"id"` + ID string `json:"id"` + LastOnline time.Time `json:"last_online"` } type CmdVerb uint8 diff --git a/manager/server.go b/manager/server.go index 70a2b00..38aa77f 100644 --- a/manager/server.go +++ b/manager/server.go @@ -2,11 +2,13 @@ package manager import ( "fmt" - "github.com/gin-gonic/gin" - . "github.com/tuna/tunasync/internal" "net/http" "sync" "time" + + "github.com/gin-gonic/gin" + + . "github.com/tuna/tunasync/internal" ) const ( @@ -20,8 +22,9 @@ const ( ) type worker struct { - ID string `json:"id"` // worker name - Token string `json:"token"` // session token + ID string `json:"id"` // worker name + Token string `json:"token"` // session token + LastOnline time.Time `json:"last_online"` // last seen } var ( @@ -62,7 +65,7 @@ func (s *managerServer) listWorkers(c *gin.Context) { } for _, w := range workers { workerInfos = append(workerInfos, - WorkerInfoMsg{w.ID}) + WorkerInfoMsg{w.ID, w.LastOnline}) } c.JSON(http.StatusOK, workerInfos) }