Commit ff408e3d authored by Peter-Jan Brone's avatar Peter-Jan Brone

Fix PT update

parent 14c4f1e4
Pipeline #152473298 passed with stages
in 44 minutes and 6 seconds
......@@ -10,19 +10,6 @@ import (
// updateTimeInterval defines the amount of time after which we'll update the
// host's prices. This is a temporary variable and will be replaced when we add
// a duration to the host's price table. For now it's just half of the
// rpcPriceGuaranteePeriod set on the host
// TODO: Need to switch to setting the price table update based on the host
// timeout instead.
var updateTimeInterval = build.Select(build.Var{
Standard: 5 * time.Minute,
Dev: 3 * time.Minute,
Testing: 7 * time.Second,
type (
// workerPriceTable contains a price table and some information related to
// retrieving the next update.
......@@ -86,7 +73,7 @@ func (w *worker) staticSetPriceTable(pt *workerPriceTable) {
// before the current time, and the price table expiry defaults to the zero
// time.
func (wpt *workerPriceTable) staticValid() bool {
return time.Now().After(wpt.staticExpiryTime)
return time.Now().Before(wpt.staticExpiryTime)
// managedUpdatePriceTable performs the UpdatePriceTableRPC on the host.
......@@ -197,13 +184,21 @@ func (w *worker) staticUpdatePriceTable() {
// Calculate the expiry time and set the update time to be half of the
// expiry window to ensure we update the PT before it expires
now := time.Now()
expiryTime := now.Add(pt.Validity)
expiryHalfTimeInS := (expiryTime.Unix() - now.Unix()) / 2
expiryHalfTime := time.Duration(expiryHalfTimeInS) * time.Second
newUpdateTime := time.Now().Add(expiryHalfTime)
// Update the price table. We preserve the recent error even though there
// has not been an error for debugging purposes, if there has been an error
// previously the devs like to be able to see what it was.
wpt := &workerPriceTable{
staticPriceTable: pt,
staticExpiryTime: time.Now().Add(pt.Validity),
staticUpdateTime: time.Now().Add(updateTimeInterval),
staticExpiryTime: expiryTime,
staticUpdateTime: newUpdateTime,
staticConsecutiveFailures: 0,
staticRecentErr: currentPT.staticRecentErr,
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment