// Refresh retrieves and parses API data from Poloniex.
555550
func (poloniex *PoloniexExchange) Refresh() {
	poloniex.LogRequest()

	var response map[string]*PoloniexPair
	err := poloniex.fetch(poloniex.requests.price, &response)
	if err != nil {
		poloniex.fail("Fetch", err)
		return
	}
	market, ok := response[poloniex.CurrencyPair]
	if !ok {
		poloniex.fail("Market not in response", fmt.Errorf("Response did not have expected CurrencyPair %s", poloniex.CurrencyPair))
		return
	}
	price, err := strconv.ParseFloat(market.Last, 64)
	if err != nil {
		poloniex.fail(fmt.Sprintf("Failed to parse float from Last=%s", market.Last), err)
		return
	}
	baseVolume, err := strconv.ParseFloat(market.BaseVolume, 64)
	if err != nil {
		poloniex.fail(fmt.Sprintf("Failed to parse float from BaseVolume=%s", market.BaseVolume), err)
		return
	}
	volume, err := strconv.ParseFloat(market.QuoteVolume, 64)
	if err != nil {
		poloniex.fail(fmt.Sprintf("Failed to parse float from QuoteVolume=%s", market.QuoteVolume), err)
		return
	}
	percentChange, err := strconv.ParseFloat(market.PercentChange, 64)
	if err != nil {
		poloniex.fail(fmt.Sprintf("Failed to parse float from PercentChange=%s", market.PercentChange), err)
		return
	}
	oldPrice := price / (1 + percentChange)

	// Depth chart
	// Check to see if the websocket has been initialized
	var skipHttp, skipBotUpdate bool
	var depth *DepthData
	if !poloniex.wsListening() {
		if poloniex.wsFailed() {
			errCount := poloniex.wsErrorCount()
			if errCount < poloniexMaxErrors {
				// Try to connect, but don't wait for the response. Grab the order
				// book over HTTP anyway.
				poloniex.connectWs()
			} else if errCount == poloniexMaxErrors {
				log.Errorf("Poloniex websocket being disabled. Too many errors")
			}
		} else {
			// Connection has not been initialized. Trigger a silent update, since an
			// update will be triggered on initial websocket message, which contains
			// the full orderbook.
			skipHttp = true
			skipBotUpdate = true
			log.Tracef("Initializing websocket connection for poloniex")
		}
	} else { // Websocket is listening
		depth = poloniex.wsDepths()
		skipHttp = true
	}

	// If not expecting depth data from the websocket, grab it from HTTP
	if !skipHttp {
		depthResponse := new(PoloniexDepthResponse)
		err = poloniex.fetch(poloniex.requests.depth, depthResponse)
		if err != nil {
			log.Errorf("Poloniex depth chart fetch error: %v", err)
		}
		depth = depthResponse.translate()
	}

	// Candlesticks
	state := poloniex.state()

	candlesticks := map[candlestickKey]Candlesticks{}
	for bin, req := range poloniex.requests.candlesticks {
		oldSticks, found := state.Candlesticks[bin]
		if !found || oldSticks.needsUpdate(bin) {
			log.Tracef("Signalling candlestick update for %s, bin size %s", poloniex.token, bin)
			response := new(PoloniexCandlestickResponse)
			err := poloniex.fetch(req, response)
			if err != nil {
				log.Errorf("Error retrieving candlestick data from poloniex for bin size %s: %v", string(bin), err)
				continue
			}

			sticks := response.translate()
			if !found || sticks.time().After(oldSticks.time()) {
				candlesticks[bin] = sticks
			}
		}
	}

	update := &ExchangeState{
		Price:        price,
		BaseVolume:   baseVolume,
		Volume:       volume,
		Change:       price - oldPrice,
		Depth:        depth,
		Candlesticks: candlesticks,
	}
	if skipBotUpdate {
		poloniex.SilentUpdate(update)
		poloniex.connectWs()
	} else {
		poloniex.Update(update)
	}

}
293016
func (s *RemoteApplication) Refresh() error {
	applications, closer := s.st.db().GetCollection(remoteApplicationsC)
	defer closer()

	err := applications.FindId(s.doc.DocID).One(&s.doc)
	if err == mgo.ErrNotFound {
		return errors.NotFoundf("remote application %q", s)
	}
	if err != nil {
		return fmt.Errorf("cannot refresh application %q: %v", s, err)
	}
	return nil
}
887072
func (info *UpgradeInfo) Refresh() error {
	doc, err := currentUpgradeInfoDoc(info.st)
	if err != nil {
		return errors.Trace(err)
	}
	info.doc = *doc
	return nil
}
691656
func (conn *Connection) Refresh() (err error) {
	urlValues := url.Values{}

	urlValues.Set("grant_type", "password")
	urlValues.Set("client_id", conn.ConsumerKey)
	urlValues.Set("client_secret", conn.ConsumerSecret)
	urlValues.Set("username", conn.Username)
	urlValues.Set("password", conn.Password)

	resp, err := http.PostForm(conn.InstanceUrl+"/services/oauth2/token", urlValues)

	if err != nil {
		return err
	}

	body, err := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()

	if err != nil {
		return err
	}

	result := OAuthResponse{}

	err = json.Unmarshal(body, &result)

	if err != nil {
		return err
	}

	conn.AccessToken = result.AccessToken
	conn.InstanceUrl = result.InstanceUrl

	return nil
}
144861
func (u *modelUserEntity) Refresh() error {
	if u.user == nil {
		return nil
	}
	return u.user.Refresh()
}
545760
func (s *Sensor) Refresh() error {
	sensor, err := s.Bridge.GetSensorByIndex(s.Index)
	if err != nil {
		return err
	}

	s.State = sensor.State
	s.Config = sensor.Config
	s.SWVersion = sensor.SWVersion
	s.Name = sensor.Name
	return nil
}
672258
func (binance *BinanceExchange) Refresh() {
	binance.LogRequest()
	priceResponse := new(BinancePriceResponse)
	err := binance.fetch(binance.requests.price, priceResponse)
	if err != nil {
		binance.fail("Fetch price", err)
		return
	}
	price, err := strconv.ParseFloat(priceResponse.LastPrice, 64)
	if err != nil {
		binance.fail(fmt.Sprintf("Failed to parse float from LastPrice=%s", priceResponse.LastPrice), err)
		return
	}
	baseVolume, err := strconv.ParseFloat(priceResponse.QuoteVolume, 64)
	if err != nil {
		binance.fail(fmt.Sprintf("Failed to parse float from QuoteVolume=%s", priceResponse.QuoteVolume), err)
		return
	}

	dcrVolume, err := strconv.ParseFloat(priceResponse.Volume, 64)
	if err != nil {
		binance.fail(fmt.Sprintf("Failed to parse float from Volume=%s", priceResponse.Volume), err)
		return
	}
	priceChange, err := strconv.ParseFloat(priceResponse.PriceChange, 64)
	if err != nil {
		binance.fail(fmt.Sprintf("Failed to parse float from PriceChange=%s", priceResponse.PriceChange), err)
		return
	}

	// Get the depth chart
	depthResponse := new(BinanceDepthResponse)
	err = binance.fetch(binance.requests.depth, depthResponse)
	if err != nil {
		log.Errorf("Error retrieving depth chart data from Binance: %v", err)
	}
	depth := depthResponse.translate()

	// Grab the current state to check if candlesticks need updating
	state := binance.state()

	candlesticks := map[candlestickKey]Candlesticks{}
	for bin, req := range binance.requests.candlesticks {
		oldSticks, found := state.Candlesticks[bin]
		if !found || oldSticks.needsUpdate(bin) {
			log.Tracef("Signalling candlestick update for %s, bin size %s", binance.token, bin)
			response := new(BinanceCandlestickResponse)
			err := binance.fetch(req, response)
			if err != nil {
				log.Errorf("Error retrieving candlestick data from binance for bin size %s: %v", string(bin), err)
				continue
			}
			sticks := response.translate()

			if !found || sticks.time().After(oldSticks.time()) {
				candlesticks[bin] = sticks
			}
		}
	}

	binance.Update(&ExchangeState{
		Price:        price,
		BaseVolume:   baseVolume,
		Volume:       dcrVolume,
		Change:       priceChange,
		Stamp:        priceResponse.CloseTime / 1000,
		Candlesticks: candlesticks,
		Depth:        depth,
	})
}
399966
func (ctn *Connection) refresh() {
	ctn.idleDeadline = time.Now().Add(ctn.idleTimeout)
}
726873
func (h *Harness) Refresh() (err *utils.Error) {
	// Allow only one thread to rebuild the process
	// If multiple requests to rebuild are queued only the last one is executed on
	// So before a build is started we wait for a second to determine if
	// more requests for a build are triggered.
	// Once no more requests are triggered the build will be processed
	h.mutex.Lock()
	defer h.mutex.Unlock()

	if h.app != nil {
		h.app.Kill()
	}

	utils.Logger.Info("Rebuild Called")
	var newErr error
	h.app, newErr = Build(h.config, h.paths)
	if newErr != nil {
		utils.Logger.Error("Build detected an error", "error", newErr)
		if castErr, ok := newErr.(*utils.Error); ok {
			return castErr
		}
		err = &utils.Error{
			Title:       "App failed to start up",
			Description: err.Error(),
		}
		return
	}

	if h.useProxy {
		h.app.Port = h.port
		if err2 := h.app.Cmd(h.runMode).Start(h.config); err2 != nil {
			utils.Logger.Error("Could not start application", "error", err2)
			if err,k :=err2.(*utils.Error);k {
				return err
			}
			return &utils.Error{
				Title:       "App failed to start up",
				Description: err2.Error(),
			}
		}
	} else {
		h.app = nil
	}

	return
}
1335829
func (w *WalletState) RefreshAsync(mctx libkb.MetaContext, accountID stellar1.AccountID, reason string) error {
	a, ok := w.accountState(accountID)
	if !ok {
		return ErrAccountNotFound
	}

	// if someone calls this, they need a refresh to happen, so make
	// sure that the next refresh for this accountID isn't skipped.
	a.Lock()
	a.rtime = time.Time{}
	a.Unlock()

	select {
	case w.refreshReqs <- accountID:
	case <-time.After(200 * time.Millisecond):
		// don't wait for full channel
		mctx.Debug("refreshReqs channel clogged trying to enqueue %s for %q", accountID, reason)
		return ErrRefreshQueueFull
	}

	return nil
}
198193
func (w *WalletState) Refresh(mctx libkb.MetaContext, accountID stellar1.AccountID, reason string) error {
	a, ok := w.accountState(accountID)
	if !ok {
		return ErrAccountNotFound
	}
	return a.Refresh(mctx, w.G().NotifyRouter, reason)
}
711315
func (u *Unit) Refresh() error {
	life, err := u.st.life(u.tag)
	if err != nil {
		return err
	}
	u.life = life
	return nil
}
1274428
func (app *Application) Refresh() {
	ev := &eventAppRefresh{}
	ev.SetEventNow()
	if scr := app.screen; scr != nil {
		go func() { scr.PostEventWait(ev) }()
	}
}
623910
func (c *Cache) refresh(opts *RegisterOptions, attempt uint, t string, key string, r Request) {
	// Sanity-check, we should not schedule anything that has refresh disabled
	if !opts.Refresh {
		return
	}
	// Check if cache was stopped
	if atomic.LoadUint32(&c.stopped) == 1 {
		return
	}

	// If we're over the attempt minimum, start an exponential backoff.
	if wait := backOffWait(attempt); wait > 0 {
		time.Sleep(wait)
	}

	// If we have a timer, wait for it
	if opts.RefreshTimer > 0 {
		time.Sleep(opts.RefreshTimer)
	}

	// Trigger. The "allowNew" field is false because in the time we were
	// waiting to refresh we may have expired and got evicted. If that
	// happened, we don't want to create a new entry.
	c.fetch(t, key, r, false, attempt)
}
976518
func (sys *PolicySys) refresh(objAPI ObjectLayer) error {
	buckets, err := objAPI.ListBuckets(context.Background())
	if err != nil {
		logger.LogIf(context.Background(), err)
		return err
	}
	sys.removeDeletedBuckets(buckets)
	for _, bucket := range buckets {
		config, err := objAPI.GetBucketPolicy(context.Background(), bucket.Name)
		if err != nil {
			if _, ok := err.(BucketPolicyNotFound); ok {
				sys.Remove(bucket.Name)
			}
			continue
		}
		// This part is specifically written to handle migration
		// when the Version string is empty, this was allowed
		// in all previous minio releases but we need to migrate
		// those policies by properly setting the Version string
		// from now on.
		if config.Version == "" {
			logger.Info("Found in-consistent bucket policies, Migrating them for Bucket: (%s)", bucket.Name)
			config.Version = policy.DefaultVersion

			if err = savePolicyConfig(context.Background(), objAPI, bucket.Name, config); err != nil {
				logger.LogIf(context.Background(), err)
				return err
			}
		}
		sys.Set(bucket.Name, *config)
	}
	return nil
}
1253128
func (j *Job) Refresh() error {
	t := newTransaction()
	t.scanJobById(j.id, j)
	if err := t.exec(); err != nil {
		return err
	}
	return nil
}
294621
func (r *Relation) Refresh() error {
	result, err := r.st.relation(r.tag, r.st.unitTag)
	if err != nil {
		return err
	}
	// NOTE: The status and life cycle information are the only
	// things that can change - id, tag and endpoint
	// information are static.
	r.life = result.Life
	r.suspended = result.Suspended

	return nil
}