// Enqueue adds and element to the heap
322739
func (heap *FloatingFibonacciHeap) Enqueue(priority float64) *Entry {
	singleton := newEntry(priority)

	// Merge singleton list with heap
	heap.min = mergeLists(heap.min, singleton)
	heap.size++
	return singleton
}
917768
func (router *Distribute) Enqueue(msg *core.Message) error {
	routers := router.routers
	if len(routers) == 0 {
		return core.NewModulateResultError(
			"Router %s: no streams configured", router.GetID())
	}

	hadErrors := false
	lastRouterIdx := len(routers) - 1
	for _, targetRouter := range routers[:lastRouterIdx] {
		err := router.route(msg.Clone(), targetRouter)
		if err != nil {
			logrus.WithError(err).Errorf("%s failed to route message", router.GetID())
			hadErrors = true
		}
	}

	// Cloning is a rather expensive operation, so skip cloning for the last
	// message (not required)

	if err := router.route(msg, routers[lastRouterIdx]); err != nil {
		logrus.WithError(err).Errorf("%s failed to route message", router.GetID())
		hadErrors = true
	}

	if hadErrors {
		return core.NewModulateResultError("%s reported errors during routing process", router.GetID())
	}
	return nil
}
99648
func (t *taskQueue) enqueue(obj interface{}) {
	key, err := keyFunc(obj)
	if err != nil {
		glog.Infof("could not get key for object %+v: %v", obj, err)
		return
	}
	t.queue.Add(key)
}
651399
func (r *messageRing) Enqueue(m *Message) error {
	mSize := int64(len(m.Line))

	r.mu.Lock()
	if r.closed {
		r.mu.Unlock()
		return errClosed
	}
	if mSize+r.sizeBytes > r.maxBytes && len(r.queue) > 0 {
		r.wait.Signal()
		r.mu.Unlock()
		return nil
	}

	r.queue = append(r.queue, m)
	r.sizeBytes += mSize
	r.wait.Signal()
	r.mu.Unlock()
	return nil
}
549008
func (pq *PrefixQueue) Dequeue(prefix []byte) (*Item, error) {
	pq.Lock()
	defer pq.Unlock()

	// Check if queue is closed.
	if !pq.isOpen {
		return nil, ErrDBClosed
	}

	// Get the queue for this prefix.
	q, err := pq.getQueue(prefix)
	if err != nil {
		return nil, err
	}

	// Try to get the next item in the queue.
	item, err := pq.getItemByPrefixID(prefix, q.Head+1)
	if err != nil {
		return nil, err
	}

	// Remove this item from the queue.
	if err := pq.db.Delete(item.Key, nil); err != nil {
		return nil, err
	}

	// Increment head position and decrement prefix queue size.
	q.Head++
	pq.size--

	// Save the queue.
	if err := pq.saveQueue(prefix, q); err != nil {
		return nil, err
	}

	// Save main prefix queue data.
	if err := pq.save(); err != nil {
		return nil, err
	}

	return item, nil
}
813538
func (s *CreateJobInput) SetQueue(v string) *CreateJobInput {
	s.Queue = &v
	return s
}
831573
func (w *watchQueue) Enqueue(key string, kvp *kvdb.KVPair, err error) {
	w.m.Lock()
	w.updates.PushBack(&watchUpdate{key: key, kvp: kvp, err: err})
	w.cv.Signal()
	w.m.Unlock()
}
860054
func (q *Queue) Enqueue(cid cid.Cid) {
	select {
	case q.enqueue <- cid:
	case <-q.ctx.Done():
	}
}
357863
func (s *SliceQueue) Dequeue() (interface{}, error) {
	if s.IsEmpty() {
		return nil, errors.New("unable to dequeue element, queue is empty")
	}

	item := s.backing[0]
	// https://github.com/golang/go/wiki/SliceTricks
	s.backing = append(s.backing[:0], s.backing[1:]...)
	s.size--
	return item, nil
}
1037209
func (s *ServiceController) enqueueService(obj interface{}) {
	key, err := controller.KeyFunc(obj)
	if err != nil {
		klog.Errorf("Couldn't get key for object %#v: %v", obj, err)
		return
	}
	s.queue.Add(key)
}
338352
func (pq *PriorityQueue) EnqueueString(priority uint8, value string) (*PriorityItem, error) {
	return pq.Enqueue(priority, []byte(value))
}
891632
func (c *RedisClient) Enqueue(jobIds ...string) error {

	args := redis.Args{}
	args.AddFlat(jobIds)
	_, err := c.conn.Do("ENQUEUE", args)
	return err
}
959658
func (e *EndpointController) enqueueService(obj interface{}) {
	key, err := controller.KeyFunc(obj)
	if err != nil {
		utilruntime.HandleError(fmt.Errorf("Couldn't get key for object %+v: %v", obj, err))
		return
	}

	e.queue.Add(key)
}
498168
func (b *PQueue) Enqueue(priority int, message *Message) error {
	k := make([]byte, 8)
	binary.BigEndian.PutUint64(k, aKey.Get())
	return b.enqueueMessage(priority, k, message)
}
471716
func (pq *PrefixQueue) EnqueueString(prefix, value string) (*Item, error) {
	return pq.Enqueue([]byte(prefix), []byte(value))
}
1312610
func (s *Scheduler) enqueue(t *api.Task) {
	s.unassignedTasks[t.ID] = t
}
1076172
func EnqueueQueueItem(p *redis.Pool, db sqlx.Ext, qi storage.MulticastQueueItem) error {
	// Get multicast-group and lock it.
	mg, err := storage.GetMulticastGroup(db, qi.MulticastGroupID, true)
	if err != nil {
		return errors.Wrap(err, "get multicast-group error")
	}

	if qi.FCnt < mg.FCnt {
		return ErrInvalidFCnt
	}

	mg.FCnt = qi.FCnt + 1
	if err := storage.UpdateMulticastGroup(db, &mg); err != nil {
		return errors.Wrap(err, "update multicast-group error")
	}

	// get DevEUIs within the multicast-group.
	devEUIs, err := storage.GetDevEUIsForMulticastGroup(db, qi.MulticastGroupID)
	if err != nil {
		return errors.Wrap(err, "get deveuis for multicast-group error")
	}

	rxInfoSets, err := storage.GetDeviceGatewayRXInfoSetForDevEUIs(p, devEUIs)
	if err != nil {
		return errors.Wrap(err, "get device gateway rx-info set for deveuis errors")
	}

	gatewayIDs, err := GetMinimumGatewaySet(rxInfoSets)
	if err != nil {
		return errors.Wrap(err, "get minimum gateway set error")
	}

	// for each gateway we increment the schedule_at timestamp with one second
	// to avoid colissions.
	if mg.GroupType == storage.MulticastGroupC {
		ts, err := storage.GetMaxScheduleAtForMulticastGroup(db, mg.ID)
		if err != nil {
			return errors.Wrap(err, "get maximum schedule at error")
		}

		if ts.IsZero() {
			ts = time.Now()
		}

		for _, gatewayID := range gatewayIDs {
			ts = ts.Add(downlinkLockDuration)
			qi.GatewayID = gatewayID
			qi.ScheduleAt = ts
			if err = storage.CreateMulticastQueueItem(db, &qi); err != nil {
				return errors.Wrap(err, "create multicast queue-item error")
			}
		}
	}

	// for each gateway the use the next ping-slot
	if mg.GroupType == storage.MulticastGroupB {
		var pingSlotNb int
		if mg.PingSlotPeriod != 0 {
			pingSlotNb = (1 << 12) / mg.PingSlotPeriod
		}

		scheduleTS, err := storage.GetMaxEmitAtTimeSinceGPSEpochForMulticastGroup(db, mg.ID)
		if err != nil {
			return errors.Wrap(err, "get maximum emit at time since gps epoch error")
		}

		if scheduleTS == 0 {
			scheduleTS = gps.Time(time.Now().Add(classBEnqueueMargin)).TimeSinceGPSEpoch()
		}

		for _, gatewayID := range gatewayIDs {
			scheduleTS, err = classb.GetNextPingSlotAfter(scheduleTS, mg.MCAddr, pingSlotNb)
			if err != nil {
				return errors.Wrap(err, "get next ping-slot after error")
			}

			qi.EmitAtTimeSinceGPSEpoch = &scheduleTS
			qi.ScheduleAt = time.Time(gps.NewFromTimeSinceGPSEpoch(scheduleTS)).Add(-2 * schedulerInterval)
			qi.GatewayID = gatewayID

			if err = storage.CreateMulticastQueueItem(db, &qi); err != nil {
				return errors.Wrap(err, "create multicast queue-item error")
			}
		}
	}

	return nil
}