Resolve issues

This commit is contained in:
M Essam Hamed
2025-10-08 19:33:31 +03:00
parent 723c418966
commit b37ba44015
3 changed files with 21 additions and 6 deletions

View File

@@ -61,11 +61,6 @@ func NewUpdateManager(statusRecorder *peer.Status) *UpdateManager {
return manager return manager
} }
func (u *UpdateManager) WithCustomVersionUpdate(versionUpdate UpdateInterface) *UpdateManager {
u.update = versionUpdate
return u
}
func (u *UpdateManager) Start(ctx context.Context) { func (u *UpdateManager) Start(ctx context.Context) {
if u.cancel != nil { if u.cancel != nil {
log.Errorf("UpdateManager already started") log.Errorf("UpdateManager already started")
@@ -124,10 +119,12 @@ func (u *UpdateManager) Stop() {
} }
u.cancel() u.cancel()
u.expectedVersionMutex.Lock()
if u.update != nil { if u.update != nil {
u.update.StopWatch() u.update.StopWatch()
u.update = nil u.update = nil
} }
u.expectedVersionMutex.Unlock()
u.wg.Wait() u.wg.Wait()
} }
@@ -151,6 +148,9 @@ func (u *UpdateManager) handleUpdate(ctx context.Context) {
var updateVersion *v.Version var updateVersion *v.Version
u.expectedVersionMutex.Lock() u.expectedVersionMutex.Lock()
if u.update == nil {
return
}
expectedVersion := u.expectedVersion expectedVersion := u.expectedVersion
useLatest := u.updateToLatestVersion useLatest := u.updateToLatestVersion
curLatestVersion := u.update.LatestVersion() curLatestVersion := u.update.LatestVersion()
@@ -176,7 +176,7 @@ func (u *UpdateManager) handleUpdate(ctx context.Context) {
return return
} }
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(time.Minute)) ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel() defer cancel()
u.lastTrigger = time.Now() u.lastTrigger = time.Now()

View File

@@ -8,6 +8,11 @@ import (
"time" "time"
) )
func (u *UpdateManager) WithCustomVersionUpdate(versionUpdate UpdateInterface) *UpdateManager {
u.update = versionUpdate
return u
}
type versionUpdateMock struct { type versionUpdateMock struct {
latestVersion *v.Version latestVersion *v.Version
onUpdate func() onUpdate func()

View File

@@ -0,0 +1,10 @@
//go:build js
package updatemanager
import "context"
func triggerUpdate(ctx context.Context, targetVersion string) error {
// TODO: Implement
return nil
}