mirror of
https://github.com/tuna/tunasync.git
synced 2025-06-14 13:32:43 +00:00
Refresh worker LastOnline when worker updates
This commit is contained in:
parent
b4b81ef7e9
commit
fd274cc976
@ -17,6 +17,7 @@ type dbAdapter interface {
|
|||||||
GetWorker(workerID string) (WorkerStatus, error)
|
GetWorker(workerID string) (WorkerStatus, error)
|
||||||
DeleteWorker(workerID string) error
|
DeleteWorker(workerID string) error
|
||||||
CreateWorker(w WorkerStatus) (WorkerStatus, error)
|
CreateWorker(w WorkerStatus) (WorkerStatus, error)
|
||||||
|
RefreshWorker(workerID string) (WorkerStatus, error)
|
||||||
UpdateMirrorStatus(workerID, mirrorID string, status MirrorStatus) (MirrorStatus, error)
|
UpdateMirrorStatus(workerID, mirrorID string, status MirrorStatus) (MirrorStatus, error)
|
||||||
GetMirrorStatus(workerID, mirrorID string) (MirrorStatus, error)
|
GetMirrorStatus(workerID, mirrorID string) (MirrorStatus, error)
|
||||||
ListMirrorStatus(workerID string) ([]MirrorStatus, error)
|
ListMirrorStatus(workerID string) ([]MirrorStatus, error)
|
||||||
@ -125,6 +126,15 @@ func (b *boltAdapter) CreateWorker(w WorkerStatus) (WorkerStatus, error) {
|
|||||||
return w, err
|
return w, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *boltAdapter) RefreshWorker(workerID string) (w WorkerStatus, err error) {
|
||||||
|
w, err = b.GetWorker(workerID)
|
||||||
|
if err == nil {
|
||||||
|
w.LastOnline = time.Now()
|
||||||
|
w, err = b.CreateWorker(w)
|
||||||
|
}
|
||||||
|
return w, err
|
||||||
|
}
|
||||||
|
|
||||||
func (b *boltAdapter) UpdateMirrorStatus(workerID, mirrorID string, status MirrorStatus) (MirrorStatus, error) {
|
func (b *boltAdapter) UpdateMirrorStatus(workerID, mirrorID string, status MirrorStatus) (MirrorStatus, error) {
|
||||||
id := mirrorID + "/" + workerID
|
id := mirrorID + "/" + workerID
|
||||||
err := b.db.Update(func(tx *bolt.Tx) error {
|
err := b.db.Update(func(tx *bolt.Tx) error {
|
||||||
|
@ -270,6 +270,7 @@ func (s *Manager) updateSchedulesOfWorker(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.rwmu.RLock()
|
s.rwmu.RLock()
|
||||||
|
s.adapter.RefreshWorker(workerID)
|
||||||
curStatus, err := s.adapter.GetMirrorStatus(workerID, mirrorName)
|
curStatus, err := s.adapter.GetMirrorStatus(workerID, mirrorName)
|
||||||
s.rwmu.RUnlock()
|
s.rwmu.RUnlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -314,6 +315,7 @@ func (s *Manager) updateJobOfWorker(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.rwmu.RLock()
|
s.rwmu.RLock()
|
||||||
|
s.adapter.RefreshWorker(workerID)
|
||||||
curStatus, _ := s.adapter.GetMirrorStatus(workerID, mirrorName)
|
curStatus, _ := s.adapter.GetMirrorStatus(workerID, mirrorName)
|
||||||
s.rwmu.RUnlock()
|
s.rwmu.RUnlock()
|
||||||
|
|
||||||
@ -376,6 +378,7 @@ func (s *Manager) updateMirrorSize(c *gin.Context) {
|
|||||||
|
|
||||||
mirrorName := msg.Name
|
mirrorName := msg.Name
|
||||||
s.rwmu.RLock()
|
s.rwmu.RLock()
|
||||||
|
s.adapter.RefreshWorker(workerID)
|
||||||
status, err := s.adapter.GetMirrorStatus(workerID, mirrorName)
|
status, err := s.adapter.GetMirrorStatus(workerID, mirrorName)
|
||||||
s.rwmu.RUnlock()
|
s.rwmu.RUnlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user