Merge pull request #50 from coolljt0725/fix_stop
updater: fix type ctrl^C not stop updating
This commit is contained in:
commit
231e16a72f
@ -61,6 +61,7 @@ func Run(config *config.UpdaterConfig, st *utils.Stopper) {
|
|||||||
// is no last update time stored in database (first update) or if an error
|
// is no last update time stored in database (first update) or if an error
|
||||||
// occurs.
|
// occurs.
|
||||||
var nextUpdate time.Time
|
var nextUpdate time.Time
|
||||||
|
var stop bool
|
||||||
if lastUpdate := getLastUpdate(); !lastUpdate.IsZero() {
|
if lastUpdate := getLastUpdate(); !lastUpdate.IsZero() {
|
||||||
nextUpdate = lastUpdate.Add(config.Interval)
|
nextUpdate = lastUpdate.Add(config.Interval)
|
||||||
} else {
|
} else {
|
||||||
@ -80,19 +81,24 @@ func Run(config *config.UpdaterConfig, st *utils.Stopper) {
|
|||||||
doneC <- true
|
doneC <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for done := false; !done; {
|
for done := false; !done && !stop; {
|
||||||
select {
|
select {
|
||||||
case <-doneC:
|
case <-doneC:
|
||||||
done = true
|
done = true
|
||||||
case <-time.After(refreshLockDuration):
|
case <-time.After(refreshLockDuration):
|
||||||
// Refresh the lock until the update is done.
|
// Refresh the lock until the update is done.
|
||||||
database.Lock(flagName, lockDuration, whoAmI)
|
database.Lock(flagName, lockDuration, whoAmI)
|
||||||
|
case <-st.Chan():
|
||||||
|
stop = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock the update.
|
// Unlock the update.
|
||||||
database.Unlock(flagName, whoAmI)
|
database.Unlock(flagName, whoAmI)
|
||||||
|
|
||||||
|
if stop {
|
||||||
|
break
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
lockOwner, lockExpiration, err := database.LockInfo(flagName)
|
lockOwner, lockExpiration, err := database.LockInfo(flagName)
|
||||||
|
Loading…
Reference in New Issue
Block a user