Ejemplo n.º 1
0
// Pop first available messages.
// Will return nil if there are no messages available.
func (pq *PQueue) Pop(params []string) iface.IResponse {
	var err *common.ErrorResponse
	var limit int64 = 1
	lockTimeout := pq.config.PopLockTimeout

	for len(params) > 0 {
		p := params[0]
		switch p {
		case PRM_LOCK_TIMEOUT:
			params, lockTimeout, err = common.ParseInt64Params(params, 0, pq.config.PopLockTimeout)
		case PRM_LIMIT:
			params, limit, err = common.ParseInt64Params(params, 1, conf.CFG.PQueueConfig.MaxPopBatchSize)
		default:
			return makeUnknownParamResponse(params[0])
		}
		if err != nil {
			return err
		}
	}
	return common.NewItemsResponse(pq.popMessages(lockTimeout, limit))
}
Ejemplo n.º 2
0
// PopWait pops up to specified number of messages, if there are no available messages.
// It will wait until either new message is pushed or wait time exceeded.
func (pq *PQueue) PopWait(params []string) iface.IResponse {
	var err *common.ErrorResponse
	var limit int64 = 1
	var popWaitTimeout int64 = 1000
	var lockTimeout int64 = pq.config.PopLockTimeout

	for len(params) > 0 {
		switch params[0] {
		case PRM_LOCK_TIMEOUT:
			params, lockTimeout, err = common.ParseInt64Params(params, 0, 24*1000*3600)
		case PRM_LIMIT:
			params, limit, err = common.ParseInt64Params(params, 1, conf.CFG.PQueueConfig.MaxPopBatchSize)
		case PRM_POP_WAIT_TIMEOUT:
			params, popWaitTimeout, err = common.ParseInt64Params(params, 1, conf.CFG.PQueueConfig.MaxPopWaitTimeout)
		default:
			return makeUnknownParamResponse(params[0])
		}
		if err != nil {
			return err
		}
	}

	return common.NewItemsResponse(pq.popWaitItems(lockTimeout, popWaitTimeout, limit))
}