コード例 #1
0
ファイル: commands.go プロジェクト: mc0/okq
func qstatus(client *clients.Client, args []string) (interface{}, error) {
	var queueNames []string
	if len(args) == 0 {
		queueNames = db.AllQueueNames()
		sort.Strings(queueNames)
	} else {
		queueNames = args
	}

	queueInfos := make([][]interface{}, 0, len(queueNames))
	for i := range queueNames {
		queueName := queueNames[i]

		claimedCount := 0
		availableCount := 0
		totalCount := 0
		consumerCount := int64(0)

		unclaimedKey := db.UnclaimedKey(queueName)
		claimedKey := db.ClaimedKey(queueName)

		claimedCount, err := db.Inst.Cmd("LLEN", claimedKey).Int()
		if err != nil {
			return nil, fmt.Errorf("QSTATUS LLEN claimed: %s", err)
		}

		availableCount, err = db.Inst.Cmd("LLEN", unclaimedKey).Int()
		if err != nil {
			return nil, fmt.Errorf("QSTATUS LLEN unclaimed: %s", err)
		}

		totalCount = availableCount + claimedCount

		consumerCount, err = consumers.QueueConsumerCount(queueName)
		if err != nil {
			return nil, fmt.Errorf("QSTATUS QueueConsumerCount: %s", err)
		}

		queueInfos = append(queueInfos, []interface{}{
			queueName,
			int64(totalCount),
			int64(claimedCount),
			consumerCount,
		})
	}

	return queueInfos, nil
}
コード例 #2
0
ファイル: restore.go プロジェクト: mc0/okq
func validateClaimedEvents() {
	log.L.Debug("validating claimed events")

	queueNames := db.AllQueueNames()

	for i := range queueNames {
		queueName := queueNames[i]
		claimedKey := db.ClaimedKey(queueName)

		// get the presumably oldest 50 items
		var eventIDs []string
		eventIDs, err := db.Inst.Cmd("LRANGE", claimedKey, -50, -1).List()
		if err != nil {
			log.L.Printf("ERR lrange redis replied %q", err)
			return
		} else if len(eventIDs) == 0 {
			continue
		}

		var locks []interface{}
		for i := range eventIDs {
			lockKey := db.ItemLockKey(queueName, eventIDs[i])
			locks = append(locks, lockKey)
		}

		var locksList [][]byte
		locksList, err = db.Inst.Cmd("MGET", locks...).ListBytes()
		if err != nil {
			log.L.Printf("ERR mget redis replied %q", err)
			return
		}

		for i := range locksList {
			if locksList[i] == nil {
				err = restoreEventToQueue(queueName, eventIDs[i])
				if err != nil {
					return
				}
			}
		}
	}
}