ソースを参照

feature(manager): add LastOnline feild to worker struct

walkerning 9 年 前
コミット
00eddc3066
2 ファイル変更10 行追加6 行削除
  1. 2 1
      internal/msg.go
  2. 8 5
      manager/server.go

+ 2 - 1
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

+ 8 - 5
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)
 }