Exemple #1
0
    async def detect(self):
        self.context.request.prevent_result_storage = True
        try:
            if not QueuedDetector.queue:
                redis = Redis(
                    host=self.context.config.REDIS_QUEUE_SERVER_HOST,
                    port=self.context.config.REDIS_QUEUE_SERVER_PORT,
                    db=self.context.config.REDIS_QUEUE_SERVER_DB,
                    password=self.context.config.REDIS_QUEUE_SERVER_PASSWORD,
                )
                QueuedDetector.queue = UniqueQueue(server=redis)

            QueuedDetector.queue.enqueue_unique_from_string(
                "remotecv.pyres_tasks.DetectTask",
                "Detect",
                args=[self.detection_type, self.context.request.image_url],
                key=self.context.request.image_url,
            )
        except RedisError:
            self.context.request.detection_error = True
            QueuedDetector.queue = None
            logger.exception("Redis Error")

        # Error or not we return an empty list as detection
        # will be done later
        return []
Exemple #2
0
    def detect(self, callback):
        self.context.request.prevent_result_storage = True
        try:
            if not QueuedDetector.redis:
                QueuedDetector.redis = Redis(host=self.context.config.REDIS_QUEUE_SERVER_HOST,
                                             port=self.context.config.REDIS_QUEUE_SERVER_PORT,
                                             db=self.context.config.REDIS_QUEUE_SERVER_DB,
                                             password=self.context.config.REDIS_QUEUE_SERVER_PASSWORD)

            queue = UniqueQueue(server=QueuedDetector.redis)
            queue.enqueue_unique_from_string('remotecv.pyres_tasks.DetectTask', 'Detect',
                    args=[self.detection_type, self.context.request.image_url],
                    key=self.context.request.image_url)
        except RedisError:
            self.context.request.detection_error = True
            QueuedDetector.redis = None
            logger.exception('Redis Error')
        finally:
            callback([])
Exemple #3
0
class QueuedDetector(BaseDetector):
    queue = UniqueQueue()

    def detect(self, callback):
        self.queue.enqueue(pyres_tasks.DetectTask, self.detection_type,
                           self.context.request.image_url,
                           self.context.request.crop['left'],
                           self.context.request.crop['top'],
                           self.context.request.crop['right'],
                           self.context.request.crop['bottom'])
        self.context.prevent_result_storage = True
        callback([])
Exemple #4
0
    def detect(self, callback):
        self.context.request.prevent_result_storage = True
        try:
            if not QueuedDetector.redis:
                QueuedDetector.redis = Redis(
                    host=self.context.config.REDIS_QUEUE_SERVER_HOST,
                    port=self.context.config.REDIS_QUEUE_SERVER_PORT,
                    db=self.context.config.REDIS_QUEUE_SERVER_DB,
                    password=self.context.config.REDIS_QUEUE_SERVER_PASSWORD)

            queue = UniqueQueue(server=QueuedDetector.redis)
            queue.enqueue_unique_from_string(
                'remotecv.pyres_tasks.DetectTask',
                'Detect',
                args=[self.detection_type, self.context.request.image_url],
                key=self.context.request.image_url)
        except RedisError:
            self.context.request.detection_error = True
            QueuedDetector.redis = None
            logger.exception('Redis Error')
        finally:
            callback([])
Exemple #5
0
 def get(self):
     self.clear()
     response = [{'name': 'REMOTECV', 'quantity': 0}]
     try:
         if not MainHandler.queue:
             redis = Redis(host=config.redis_host,
                           port=config.redis_port,
                           db=config.redis_database,
                           password=config.redis_password)
             MainHandler.queue = UniqueQueue(server=redis)
         jobs = MainHandler.queue.info().get('pending')
         response[0]['quantity'] = jobs
         self.write(json.dumps(response))
     except RedisError:
         MainHandler.queue = None
         logger.exception('Could not connect to Redis')
         self.write(json.dumps(response))
     finally:
         self.set_header('Content-Type', 'application/json')
Exemple #6
0
    async def detect(self):
        self.context.request.prevent_result_storage = True
        try:
            if not QueuedDetector.queue:
                redis = self.redis_client()
                QueuedDetector.queue = UniqueQueue(server=redis)

            QueuedDetector.queue.enqueue_unique_from_string(
                "remotecv.pyres_tasks.DetectTask",
                "Detect",
                args=[self.detection_type, self.context.request.image_url],
                key=self.context.request.image_url,
            )
        except RedisError:
            self.context.request.detection_error = True
            QueuedDetector.queue = None
            logger.exception("Redis Error")

        # Error or not we return an empty list as detection
        # will be done later
        return []