예제 #1
0
파일: status.py 프로젝트: saroj3k/koku
    def _get_celery_queue_data(self):
        """Fetch scheduled, reserved, and running tasks."""
        tasks = {}
        try:
            conn = celery_app.connection()
            inspector = celery_app.control.inspect(connection=conn, timeout=1)

            scheduled = inspector.scheduled()
            scheduled_count = 0
            if scheduled:
                for task_list in scheduled.values():
                    scheduled_count += len(task_list)
            tasks["scheduled_count"] = scheduled_count

            reserved = inspector.reserved()
            reserved_count = 0
            if reserved:
                for task_list in reserved.values():
                    reserved_count += len(task_list)
            tasks["reserved_count"] = reserved_count

            active = inspector.active()
            active_count = 0
            if active:
                for task_list in active.values():
                    active_count += len(task_list)
            tasks["active_count"] = active_count
        except (ConnectionResetError, TimeoutError) as err:
            CELERY_ERRORS_COUNTER.inc()
            tasks = {"Error": str(err)}
        finally:
            if conn:
                conn.release()
        return tasks
예제 #2
0
 def _check_celery_status(self):
     """Check for celery status."""
     try:
         conn = celery_app.connection()
         inspector = celery_app.control.inspect(connection=conn, timeout=1)
         stats = inspector.stats()
         if not stats:
             stats = {'Error': CELERY_WORKER_NOT_FOUND}
     except (ConnectionResetError, TimeoutError) as err:
         stats = {'Error': str(err)}
     finally:
         if conn:
             conn.release()
     return stats
예제 #3
0
    def celery_status(self):
        """Determine the status of our connection to Celery.

        :returns: dict of celery status, or an error
        """
        # First check if our Broker is reachable
        conn = None
        try:
            conn = celery_app.connection()
            conn.heartbeat_check()
        except (ConnectionRefusedError, socket.timeout):
            return {'Error': BROKER_CONNECTION_ERROR}
        # Now check if Celery workers are running
        stats = self._check_celery_status()
        if 'Error' in stats and stats['Error'] != CELERY_WORKER_NOT_FOUND:
            stats = self._check_celery_status()
        if conn:
            conn.release()
        return stats