parent
cfa960d619
commit
bf7e1a52f2
@ -21,10 +21,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/pkg/capnslog"
|
|
||||||
"github.com/coreos/clair/database"
|
"github.com/coreos/clair/database"
|
||||||
"github.com/coreos/clair/health"
|
"github.com/coreos/clair/health"
|
||||||
"github.com/coreos/clair/utils"
|
"github.com/coreos/clair/utils"
|
||||||
|
"github.com/coreos/pkg/capnslog"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -93,23 +93,16 @@ func Run(interval time.Duration, st *utils.Stopper) {
|
|||||||
doneC <- true
|
doneC <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Refresh the lock until the update is done.
|
|
||||||
for done := false; !done; {
|
for done := false; !done; {
|
||||||
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.
|
||||||
database.Lock(flagName, lockDuration, whoAmI)
|
database.Lock(flagName, lockDuration, whoAmI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the last update time to the database and set the next update
|
|
||||||
// time.
|
|
||||||
now := time.Now().UTC()
|
|
||||||
database.UpdateFlag(flagName, strconv.FormatInt(now.Unix(), 10))
|
|
||||||
healthLatestSuccessfulUpdate = now
|
|
||||||
nextUpdate = now.Add(interval)
|
|
||||||
|
|
||||||
// Unlock the update.
|
// Unlock the update.
|
||||||
database.Unlock(flagName, whoAmI)
|
database.Unlock(flagName, whoAmI)
|
||||||
} else {
|
} else {
|
||||||
@ -252,7 +245,11 @@ func Update() {
|
|||||||
|
|
||||||
// Update health depending on the status of the fetchers.
|
// Update health depending on the status of the fetchers.
|
||||||
updateHealth(status)
|
updateHealth(status)
|
||||||
|
if status {
|
||||||
|
now := time.Now().UTC()
|
||||||
|
database.UpdateFlag(flagName, strconv.FormatInt(now.Unix(), 10))
|
||||||
|
healthLatestSuccessfulUpdate = now
|
||||||
|
}
|
||||||
log.Info("update finished")
|
log.Info("update finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user