feature(manager): add LastOnline feild to worker struct

This commit is contained in:
walkerning 2016-04-25 19:05:04 +08:00 committed by bigeagle
parent 401b6a694e
commit 00eddc3066
No known key found for this signature in database
GPG Key ID: 9171A4571C27920A
2 changed files with 10 additions and 6 deletions

View File

@ -18,7 +18,8 @@ type StatusUpdateMsg struct {
// A WorkerInfoMsg is the information struct that describe // A WorkerInfoMsg is the information struct that describe
// a worker, and sent from the manager to clients. // a worker, and sent from the manager to clients.
type WorkerInfoMsg struct { type WorkerInfoMsg struct {
ID string `json:"id"` ID string `json:"id"`
LastOnline time.Time `json:"last_online"`
} }
type CmdVerb uint8 type CmdVerb uint8

View File

@ -2,11 +2,13 @@ package manager
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin"
. "github.com/tuna/tunasync/internal"
"net/http" "net/http"
"sync" "sync"
"time" "time"
"github.com/gin-gonic/gin"
. "github.com/tuna/tunasync/internal"
) )
const ( const (
@ -20,8 +22,9 @@ const (
) )
type worker struct { type worker struct {
ID string `json:"id"` // worker name ID string `json:"id"` // worker name
Token string `json:"token"` // session token Token string `json:"token"` // session token
LastOnline time.Time `json:"last_online"` // last seen
} }
var ( var (
@ -62,7 +65,7 @@ func (s *managerServer) listWorkers(c *gin.Context) {
} }
for _, w := range workers { for _, w := range workers {
workerInfos = append(workerInfos, workerInfos = append(workerInfos,
WorkerInfoMsg{w.ID}) WorkerInfoMsg{w.ID, w.LastOnline})
} }
c.JSON(http.StatusOK, workerInfos) c.JSON(http.StatusOK, workerInfos)
} }