Esempio n. 1
0
def check_redis(app_configs=None, **kwargs):
    from django_rq.queues import get_queue
    from django_rq.workers import Worker

    errors = []

    try:
        queue = get_queue()
        Worker.all(queue.connection)
    except Exception as e:
        conn_settings = queue.connection.connection_pool.connection_kwargs
        errors.append(
            checks.Critical(
                _("Could not connect to Redis (%s)" % e),
                hint=_("Make sure Redis is running on %(host)s:%(port)s" %
                       conn_settings),
                id="pootle.C001",
            ))
    else:
        if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:
            # We need to check we're not running manage.py rqworker right now..
            import sys

            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:
                errors.append(
                    checks.Warning(
                        _("No RQ Worker running."),
                        hint=_("Run new workers with manage.py rqworker"),
                        id="pootle.W001",
                    ))

    return errors
Esempio n. 2
0
def redis_is_running():
    """Checks is redis is running

    :returns: `True` if redis is running, `False` otherwise.
    """
    try:
        queue = get_queue()
        Worker.all(queue.connection)
    except ConnectionError:
        return False
    return True
Esempio n. 3
0
def rq_stats():
    queue = get_queue()
    failed_queue = get_failed_queue()
    try:
        workers = Worker.all(queue.connection)
    except ConnectionError:
        return None

    num_workers = len(workers)
    is_running = len(queue.connection.smembers(Worker.redis_workers_keys)) > 0
    if is_running:
        # Translators: this refers to the status of the background job worker
        status_msg = ungettext('Running (%d worker)', 'Running (%d workers)',
                               num_workers) % num_workers
    else:
        # Translators: this refers to the status of the background job worker
        status_msg = _('Stopped')

    result = {
        'job_count': queue.count,
        'failed_job_count': failed_queue.count,
        'is_running': is_running,
        'status_msg': status_msg,
    }

    return result
Esempio n. 4
0
def rq_stats():
    queue = get_queue()
    failed_queue = get_failed_queue()
    try:
        workers = Worker.all(queue.connection)
    except ConnectionError:
        return None

    num_workers = len(workers)
    is_running = len(queue.connection.smembers(Worker.redis_workers_keys)) > 0
    if is_running:
        # Translators: this refers to the status of the background job worker
        status_msg = ungettext('Running (%d worker)', 'Running (%d workers)',
                               num_workers) % num_workers
    else:
        # Translators: this refers to the status of the background job worker
        status_msg = _('Stopped')

    result = {
        'job_count': queue.count,
        'failed_job_count': failed_queue.count,
        'is_running': is_running,
        'status_msg': status_msg,
    }

    return result
Esempio n. 5
0
def check_redis(app_configs=None, **kwargs):
    from django_rq.queues import get_queue
    from django_rq.workers import Worker

    errors = []

    try:
        queue = get_queue()
        workers = Worker.all(queue.connection)
    except Exception as e:
        conn_settings = queue.connection.connection_pool.connection_kwargs
        errors.append(checks.Critical(_("Could not connect to Redis (%s)") % (e),
            hint=_("Make sure Redis is running on %(host)s:%(port)s") % (conn_settings),
            id="pootle.C001",
        ))
    else:
        if not workers or workers[0].stopped:
            # We need to check we're not running manage.py rqworker right now..
            import sys
            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:
                errors.append(checks.Warning(
                    _("No RQ Worker running."),
                    hint=_("Run new workers with manage.py rqworker"),
                    id="pootle.W001",
                ))

        redis_version = queue.connection.info()["redis_version"].split(".")
        if tuple(int(x) for x in redis_version) < REDIS_MINIMUM_REQUIRED_VERSION:
            errors.append(checks.Warning(
                _("Your version of Redis is too old."),
                hint=_("Update your system's Redis server package"),
                id="pootle.W002",
            ))

    return errors
Esempio n. 6
0
def rq_stats():
    queue = get_queue()
    try:
        workers = Worker.all(queue.connection)
    except ConnectionError:
        return None

    num_workers = len(workers)
    is_running = len(queue.connection.smembers(Worker.redis_workers_keys)) > 0
    if is_running:
        # Translators: this refers to the status of the background job worker
        status_msg = (
            ungettext("Running (%d worker)", "Running (%d workers)", num_workers)
            % num_workers
        )
    else:
        # Translators: this refers to the status of the background job worker
        status_msg = _("Stopped")

    failed_job_registry = FailedJobRegistry(queue.name, queue.connection)
    result = {
        "job_count": queue.count,
        "failed_job_count": len(failed_job_registry),
        "is_running": is_running,
        "status_msg": status_msg,
    }

    return result
Esempio n. 7
0
def check_redis(app_configs=None, **kwargs):
    from django_rq.queues import get_queue
    from django_rq.workers import Worker

    errors = []

    try:
        queue = get_queue()
        Worker.all(queue.connection)
    except Exception as e:
        conn_settings = queue.connection.connection_pool.connection_kwargs
        errors.append(
            checks.Critical(
                _("Could not connect to Redis (%s)", e),
                hint=_("Make sure Redis is running on "
                       "%(host)s:%(port)s") % conn_settings,
                id="pootle.C001",
            ))
    else:
        redis_version = tuple(
            int(x)
            for x in (queue.connection.info()["redis_version"].split(".")))
        if redis_version < REDIS_MINIMUM_REQUIRED_VERSION:
            errors.append(
                checks.Critical(
                    _("Your version of Redis is too old."),
                    hint=_(
                        "Update your system's Redis server package to at least "
                        "version %s", str(REDIS_MINIMUM_REQUIRED_VERSION)),
                    id="pootle.C007",
                ))

        if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:
            # If we're not running 'pootle rqworker' report for whitelisted
            # commands
            import sys
            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:
                errors.append(
                    checks.Warning(
                        # Translators: a worker processes background tasks
                        _("No worker running."),
                        # Translators: a worker processes background tasks
                        hint=_("Run new workers with 'pootle rqworker'"),
                        id="pootle.W001",
                    ))

    return errors
Esempio n. 8
0
def test_redis_server_available():
    from django_rq.queues import get_queue
    from django_rq.workers import Worker
    from redis.exceptions import ConnectionError
    queue = get_queue()
    try:
        workers = Worker.all(queue.connection)
        return True, queue.connection.connection_pool.connection_kwargs
    except ConnectionError:
        return False, queue.connection.connection_pool.connection_kwargs
Esempio n. 9
0
def check_redis(app_configs=None, **kwargs):
    from django_rq.queues import get_queue
    from django_rq.workers import Worker

    errors = []

    try:
        queue = get_queue()
        Worker.all(queue.connection)
    except Exception as e:
        conn_settings = queue.connection.connection_pool.connection_kwargs
        errors.append(checks.Critical(
            _("Could not connect to Redis (%s)", e),
            hint=_("Make sure Redis is running on "
                   "%(host)s:%(port)s") % conn_settings,
            id="pootle.C001",
        ))
    else:
        redis_version = tuple(int(x) for x
                              in (queue.connection
                                       .info()["redis_version"].split(".")))
        if redis_version < REDIS_MINIMUM_REQUIRED_VERSION:
            errors.append(checks.Critical(
                _("Your version of Redis is too old."),
                hint=_("Update your system's Redis server package to at least "
                       "version %s", str(REDIS_MINIMUM_REQUIRED_VERSION)),
                id="pootle.C007",
            ))

        if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:
            # If we're not running 'pootle rqworker' report for whitelisted
            # commands
            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:
                errors.append(checks.Warning(
                    # Translators: a worker processes background tasks
                    _("No worker running."),
                    # Translators: a worker processes background tasks
                    hint=_("Run new workers with 'pootle rqworker'"),
                    id="pootle.W001",
                ))

    return errors
Esempio n. 10
0
def rq_stats():
    queue = get_queue()
    failed_queue = get_failed_queue()
    workers = Worker.all(queue.connection)
    is_running = False
    if len(workers) == 1:
        is_running = not workers[0].stopped

    result = {
        'job_count': queue.count,
        'failed_job_count': failed_queue.count,
        'is_running': is_running,
    }

    return result
Esempio n. 11
0
def rq_stats():
    queue = get_queue()
    failed_queue = get_failed_queue()
    workers = Worker.all(queue.connection)
    is_running = False
    if len(workers) == 1:
        is_running = not workers[0].stopped

    result = {
        'job_count': queue.count,
        'failed_job_count': failed_queue.count,
        'is_running': is_running,
    }

    return result
Esempio n. 12
0
def check_redis(app_configs=None, **kwargs):
    from django_rq.queues import get_queue
    from django_rq.workers import Worker

    errors = []

    try:
        queue = get_queue()
        workers = Worker.all(queue.connection)
    except Exception as e:
        conn_settings = queue.connection.connection_pool.connection_kwargs
        errors.append(
            checks.Critical(
                _("Could not connect to Redis (%s)") % (e),
                hint=_("Make sure Redis is running on %(host)s:%(port)s") %
                (conn_settings),
                id="pootle.C001",
            ))
    else:
        redis_version = tuple(
            int(x)
            for x in (queue.connection.info()["redis_version"].split(".")))
        if redis_version < REDIS_MINIMUM_REQUIRED_VERSION:
            errors.append(
                checks.Critical(
                    _("Your version of Redis is too old."),
                    hint=_(
                        "Update your system's Redis server package to at least "
                        "version %s" % str(REDIS_MINIMUM_REQUIRED_VERSION)),
                    id="pootle.C007",
                ))

        if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:
            # We need to check we're not running manage.py rqworker right now..
            import sys
            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:
                errors.append(
                    checks.Warning(
                        _("No RQ Worker running."),
                        hint=_("Run new workers with manage.py rqworker"),
                        id="pootle.W001",
                    ))

    return errors
Esempio n. 13
0
def test_rq_workers_running():
    from django_rq.queues import get_queue
    from django_rq.workers import Worker
    queue = get_queue()
    workers = Worker.all(queue.connection)
    return len(workers) >= 1 and not workers[0].stopped, len(workers)