velodrome/token-counter/token-counter.go
func (t TokenHandler) Process() {
	lastRate, err := t.getCoreRate()
	if err != nil {
		glog.Fatalf("%s: Couldn't get rate limits: %v", t.login, err)
	}

	for {
		halfPeriod := lastRate.Reset.Time.Sub(time.Now()) / 2
		time.Sleep(halfPeriod)
		newRate, err := t.getCoreRate()
		if err != nil {
			glog.Error("Failed to get CoreRate: ", err)
			continue
		}
		// There is a bug in GitHub. They seem to reset the Remaining value before resetting the Reset value.
		if !newRate.Reset.Time.Equal(lastRate.Reset.Time) || newRate.Remaining > lastRate.Remaining {
			if err := t.influxdb.Push(
				"github_token_count",
				map[string]string{"login": t.login},
				map[string]interface{}{"value": lastRate.Limit - lastRate.Remaining},
				lastRate.Reset.Time,
			); err != nil {
				glog.Error("Failed to push count:", err)
			}
			// Make sure the timer is properly reset, and we have time anyway
			time.Sleep(30 * time.Minute)
			for {
				newRate, err = t.getCoreRate()
				if err == nil {
					break
				}
				glog.Error("Failed to get CoreRate: ", err)
				time.Sleep(time.Minute)
			}

		}
		lastRate = newRate
	}
}
func (t TokenHandler) Process() {
	lastRate, err := t.getCoreRate()
	if err != nil {
		glog.Fatalf("%s: Couldn't get rate limits: %v", t.login, err)
	}

	for {
		halfPeriod := lastRate.Reset.Time.Sub(time.Now()) / 2
		time.Sleep(halfPeriod)
		newRate, err := t.getCoreRate()
		if err != nil {
			glog.Error("Failed to get CoreRate: ", err)
			continue
		}
		// There is a bug in GitHub. They seem to reset the Remaining value before resetting the Reset value.
		if !newRate.Reset.Time.Equal(lastRate.Reset.Time) || newRate.Remaining > lastRate.Remaining {
			if err := t.influxdb.Push(
				"github_token_count",
				map[string]string{"login": t.login},
				map[string]interface{}{"value": lastRate.Limit - lastRate.Remaining},
				lastRate.Reset.Time,
			); err != nil {
				glog.Error("Failed to push count:", err)
			}
			// Make sure the timer is properly reset, and we have time anyway
			time.Sleep(30 * time.Minute)
			for {
				newRate, err = t.getCoreRate()
				if err == nil {
					break
				}
				glog.Error("Failed to get CoreRate: ", err)
				time.Sleep(time.Minute)
			}

		}
		lastRate = newRate
	}
}
// Process does the main job:
// It tries to get the value of "Remaining" rate just before the token
// gets reset. It does that more and more often (as the reset date gets
// closer) to get the most accurate value.