Example #1
0
func (s *SQLiteStore) Update(v version.Version) (err error) {
	if v.ExactUpdate.Before(s.threshold) {
		return
	}
	_, err = s.db.Exec(
		`insert into version(key, app_id, app, ver, host,
                    instance, host_ip, last_update, exact_update)
        values(?, ?, ?, ?, ?, ?, ?, ?, ?);`,
		v.Key(), v.AppId, v.App, v.Ver, v.Host,
		v.Instance, v.HostIP, v.LastUpdate, v.ExactUpdate.UnixNano())
	return err
}
Example #2
0
func (s *MemoryStore) Update(v version.Version) (err error) {
	key := v.Key()
	_, vpresent := s.version[key]
	if v.ExactUpdate.After(s.threshold) {
		s.version[key] = v
	}

	// app map
	if as, present := s.app[v.AppId]; present {
		as.LastUpdate = v.LastUpdate
		if !vpresent {
			as.HostCount++
			s.app[v.AppId] = as
		}
	} else {
		appv := version.AppSummary{
			App:        v.App,
			AppId:      v.AppId,
			LastUpdate: v.LastUpdate,
			HostCount:  1,
		}
		s.app[v.AppId] = appv
	}

	// host map
	if hs, present := s.host[v.Host]; present {
		hs.LastUpdate = v.LastUpdate
		if !vpresent {
			hs.AppCount++
			s.host[v.Host] = hs
		}
	} else {
		hostv := version.HostSummary{
			Host:       v.Host,
			LastUpdate: v.LastUpdate,
			AppCount:   1,
		}
		s.host[v.Host] = hostv
	}
	return
}