Repository: readthedocs/readthedocs.org

Issue:
Bug in core.views.queue_info, is it used anymore?
The code in `core.views.queue_info` contains this:

``` python
            for obj in reserved['build']:
                kwrags = eval(obj['kwargs'])
                reserved_pks.append(str(kwargs['pk']))
```

So it has a typo in `kwrags`. That means the third line of the example won't pick up the correct variable. It might still succeed without a `NameError` as it might be already initialized by another for loop above in the same function.

See https://github.com/rtfd/readthedocs.org/blob/291d7d61e626c1dfb998d9e5d4e5b734a44a7024/readthedocs/core/views.py#L102

I didn't fix it straight away as it seems that the `queue_info` URL is not used anywhere in the project? Do we still have a use for it?

```
$ grep -r queue_info .
./readthedocs/core/views.py:def queue_info(request):
./readthedocs/urls.py:    url(r'^queue_info/$', 'readthedocs.core.views.queue_info', name='queue_info'),
```



Discussion:
It was mainly used for debugging celery, but we now have real monitoring
for it, so it can likely be deleted.

On Fri, Jul 31, 2015 at 4:26 AM, Gregor Müllegger notifications@github.com
wrote:

> The code in core.views.queue_info contains this:
> 
> ```
>         for obj in reserved['build']:
>             kwrags = eval(obj['kwargs'])
>             reserved_pks.append(str(kwargs['pk']))
> ```
> 
> So it has a typo in kwrags. That means the third line of the example
> won't pick up the correct variable. It might still succeed without a
> NameError as it might be already initialized by another for loop above in
> the same function.
> 
> See
> https://github.com/rtfd/readthedocs.org/blob/291d7d61e626c1dfb998d9e5d4e5b734a44a7024/readthedocs/core/views.py#L102
> 
> I didn't fix it straight away as it seems that the queue_info URL is not
> used anywhere in the project? Do we still have a use for it?
> 
> $ grep -r queue_info .
> ./readthedocs/core/views.py:def queue_info(request):
> ./readthedocs/urls.py:    url(r'^queue_info/$', 'readthedocs.core.views.queue_info', name='queue_info'),
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/rtfd/readthedocs.org/issues/1515.

## 

Eric Holscher
Maker of the internet residing in Portland, Oregon
http://ericholscher.com


Resolving patch:
diff --git a/readthedocs/core/management/commands/pull.py b/readthedocs/core/management/commands/pull.py
--- a/readthedocs/core/management/commands/pull.py
+++ b/readthedocs/core/management/commands/pull.py
@@ -6,7 +6,6 @@
 from readthedocs.builds.constants import LATEST
 from readthedocs.projects import tasks, utils
 
-import redis
 
 log = logging.getLogger(__name__)
 
diff --git a/readthedocs/core/views.py b/readthedocs/core/views.py
--- a/readthedocs/core/views.py
+++ b/readthedocs/core/views.py
@@ -16,7 +16,6 @@
 
 from haystack.query import EmptySearchQuerySet
 from haystack.query import SearchQuerySet
-from celery.task.control import inspect  # noqa: pylint false positive
 import stripe
 
 from readthedocs.builds.models import Build
@@ -35,7 +34,6 @@
 import mimetypes
 import os
 import logging
-import redis
 import re
 
 log = logging.getLogger(__name__)
@@ -77,42 +75,6 @@ def random_page(request, project_slug=None):
     return HttpResponseRedirect(url)
 
 
-def queue_depth(request):
-    r = redis.Redis(**settings.REDIS)
-    return HttpResponse(r.llen('celery'))
-
-
-def queue_info(request):
-    i = inspect()
-    active_pks = []
-    reserved_pks = []
-    resp = ""
-
-    active = i.active()
-    if active:
-        try:
-            for obj in active['build']:
-                kwargs = eval(obj['kwargs'])
-                active_pks.append(str(kwargs['pk']))
-            active_resp = "Active: %s  " % " ".join(active_pks)
-            resp += active_resp
-        except Exception, e:
-            resp += str(e)
-
-    reserved = i.reserved()
-    if reserved:
-        try:
-            for obj in reserved['build']:
-                kwrags = eval(obj['kwargs'])
-                reserved_pks.append(str(kwargs['pk']))
-            reserved_resp = " | Reserved: %s" % " ".join(reserved_pks)
-            resp += reserved_resp
-        except Exception, e:
-            resp += str(e)
-
-    return HttpResponse(resp)
-
-
 def live_builds(request):
     builds = Build.objects.filter(state='building')[:5]
     websocket_host = getattr(settings, 'WEBSOCKET_HOST', 'localhost:8088')
diff --git a/readthedocs/urls.py b/readthedocs/urls.py
--- a/readthedocs/urls.py
+++ b/readthedocs/urls.py
@@ -111,8 +111,6 @@
         name='random_page'),
     url(r'^random/$', 'readthedocs.core.views.random_page', name='random_page'),
     url(r'^sustainability/', include('readthedocs.donate.urls')),
-    url(r'^depth/$', 'readthedocs.core.views.queue_depth', name='queue_depth'),
-    url(r'^queue_info/$', 'readthedocs.core.views.queue_info', name='queue_info'),
     url(r'^live/$', 'readthedocs.core.views.live_builds', name='live_builds'),
     url(r'^500/$', 'readthedocs.core.views.divide_by_zero', name='divide_by_zero'),
     url(r'^filter/version/$',


Test patch: