コード例 #1
0
ファイル: workload.go プロジェクト: pavel-paulau/gateload
func RunPuller(c *api.SyncGatewayClient, channel, name string, wg *sync.WaitGroup) {
	defer wg.Done()

	lastSeq := fmt.Sprintf("%s:%d", channel, int(math.Max(c.GetLastSeq()-MaxFirstFetch, 0)))
	lastSeq = readFeed(c, "normal", lastSeq)

	checkpointSeqId := int64(0)
	for {
		timer := time.AfterFunc(CheckpointInverval, func() {
			checkpoint := api.Checkpoint{LastSequence: lastSeq}
			chechpointHash := fmt.Sprintf("%s-%s", name, Hash(strconv.FormatInt(checkpointSeqId, 10)))
			c.SaveCheckpoint(chechpointHash, checkpoint)
			checkpointSeqId += 1
		})
		lastSeq = readFeed(c, "longpoll", lastSeq)
		timer.Stop()
	}
}