Skip to content

Commit

Permalink
Add LastRegister to WorkerStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Sep 10, 2020
1 parent 2ba3a27 commit c8600d0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions internal/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ type MirrorStatus struct {
// A WorkerStatus is the information struct that describe
// a worker, and sent from the manager to clients.
type WorkerStatus struct {
ID string `json:"id"`
URL string `json:"url"` // worker url
Token string `json:"token"` // session token
LastOnline time.Time `json:"last_online"` // last seen
ID string `json:"id"`
URL string `json:"url"` // worker url
Token string `json:"token"` // session token
LastOnline time.Time `json:"last_online"` // last seen
LastRegister time.Time `json:"last_register"` // last register time
}

type MirrorSchedules struct {
Expand Down
1 change: 1 addition & 0 deletions manager/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestBoltAdapter(t *testing.T) {
ID: id,
Token: "token_" + id,
LastOnline: time.Now(),
LastRegister: time.Now(),
}
w, err = boltDB.CreateWorker(w)
So(err, ShouldBeNil)
Expand Down
6 changes: 4 additions & 2 deletions manager/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ func (s *Manager) listWorkers(c *gin.Context) {
for _, w := range workers {
workerInfos = append(workerInfos,
WorkerStatus{
ID: w.ID,
LastOnline: w.LastOnline,
ID: w.ID,
LastOnline: w.LastOnline,
LastRegister: w.LastRegister,
})
}
c.JSON(http.StatusOK, workerInfos)
Expand All @@ -215,6 +216,7 @@ func (s *Manager) registerWorker(c *gin.Context) {
var _worker WorkerStatus
c.BindJSON(&_worker)
_worker.LastOnline = time.Now()
_worker.LastRegister = time.Now()
newWorker, err := s.adapter.CreateWorker(_worker)
if err != nil {
err := fmt.Errorf("failed to register worker: %s",
Expand Down
1 change: 1 addition & 0 deletions worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func makeMockManagerServer(recvData chan interface{}) *gin.Engine {
var _worker WorkerStatus
c.BindJSON(&_worker)
_worker.LastOnline = time.Now()
_worker.LastRegister = time.Now()
recvData <- _worker
c.JSON(http.StatusOK, _worker)
})
Expand Down

0 comments on commit c8600d0

Please sign in to comment.