Example #1
0
    def run(self):
        queue = self.queue
        id = str(self.qid)
        logging.error('checking: ' + queue + '  ' + id)

        source_queue = 'queue::' + queue
        temp_queue = 'temp::' + self.machine_name + "::" + id + "::" + source_queue

        #To process a request which might not be done due to restart
        obj = cache.lindex(temp_queue, 0)
        if obj is not None:
            logging.error("Processing previous entry temp_queue=%s qid=%s",
                          temp_queue, str(self.qid))
            try:
                QueueProcessor.process(queue, obj)
            except Exception as e:
                logging.exception(
                    "error while processing previous entry: %s. Reason: %s",
                    obj, e.message)
                self.enqueue_in_error_queue(source_queue, id, obj)
            cache.lpop(temp_queue)

        while self.running:
            obj = None
            try:
                obj = cache.brpoplpush(source_queue, temp_queue, TIME_OUT)
            except TimeoutError:
                gevent.sleep(INTERVAL)
            except Exception as e:
                logging.exception(
                    'unable to fetch object from redis. Reason: ' + e.message)
                gevent.sleep(INTERVAL)
            if obj is not None:
                try:
                    QueueProcessor.process(queue, obj)
                except Exception as e:
                    logging.exception("error while processing: %s. Reason: %s",
                                      obj, e.message)
                    self.enqueue_in_error_queue(source_queue, id, obj)
                cache.lpop(temp_queue)
            else:
                logging.error("[%s] No entry to process. Sleeping", self.queue)
                gevent.sleep(INTERVAL)
            gevent.sleep(0)
Example #2
0
    def run(self):
        queue = self.queue
        id = str(self.qid)
        logging.error('checking: ' + queue + '  ' + id)

        source_queue = 'queue::' + queue
        temp_queue = 'temp::' + self.machine_name + "::" + id + "::" + source_queue

        #To process a request which might not be done due to restart
        obj = cache.lindex(temp_queue, 0)
        if obj is not None:
            logging.error("Processing previous entry temp_queue=%s qid=%s", temp_queue, str(self.qid))
            try:
                QueueProcessor.process(queue, obj)
            except Exception as e:
                logging.exception("error while processing previous entry: %s. Reason: %s", obj, e.message)
                self.enqueue_in_error_queue(source_queue, id, obj)
            cache.lpop(temp_queue)

        while self.running:
            obj = None
            try:
                obj = cache.brpoplpush(source_queue, temp_queue, TIME_OUT)
            except TimeoutError:
                gevent.sleep(INTERVAL)
            except Exception as e:
                logging.exception('unable to fetch object from redis. Reason: ' + e.message)
                gevent.sleep(INTERVAL)
            if obj is not None:
                try:
                    QueueProcessor.process(queue, obj)
                except Exception as e:
                    logging.exception("error while processing: %s. Reason: %s", obj, e.message)
                    self.enqueue_in_error_queue(source_queue, id, obj)
                cache.lpop(temp_queue)
            else:
                logging.error("[%s] No entry to process. Sleeping", self.queue)
                gevent.sleep(INTERVAL)
            gevent.sleep(0)