

def enqueue(self):
    now = int(time.time())
    queue_items = []
    if (self.amqp_queue_size < 100000):
        queue_items_a = queue_items.append
        LOGGER.debug(('%s:%s' % (self.heap[0][0], now)))
        while ((self.heap[0][0] < now) and (len(queue_items) < 1000)):
            job = heappop(self.heap)
            uuid = UUID(bytes=job[1][0])
            if (not (uuid.hex in self.unscheduled_items)):
                queue_items_a(job[1][0])
                new_job = ((now + job[1][1]), job[1])
                heappush(self.heap, new_job)
            else:
                self.unscheduled_items.remove(uuid.hex)
    else:
        LOGGER.critical(('AMQP queue is at or beyond max limit (%d/100000)' % self.amqp_queue_size))
    if queue_items:
        LOGGER.info(('Found %d new uuids, adding them to the queue' % len(queue_items)))
        msgs = [Content(uuid) for uuid in queue_items]
        deferreds = [self.chan.basic_publish(exchange=self.amqp_exchange, content=msg) for msg in msgs]
        d = DeferredList(deferreds, consumeErrors=True)
        d.addCallbacks(self._addToQueueComplete, self._addToQueueErr)
    else:
        self.enqueueCallLater = reactor.callLater(1, self.enqueue)

dataset/ETHPy150Open wehriam/awspider/awspider/servers2/scheduler.py SchedulerServer.enqueue/original