Skip to content

Commit

Permalink
Implements Inspect.conf command for getting worker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mher committed Jan 19, 2013
1 parent 2926a62 commit 8f3ddf0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions celery/app/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def ping(self):
def active_queues(self):
return self._request('active_queues')

def conf(self):
return self._request('dump_conf')

class Control(object):
Mailbox = Mailbox
Expand Down
31 changes: 31 additions & 0 deletions celery/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import sys
import traceback
import warnings
import types
import datetime

from functools import partial, wraps
from inspect import getargspec
Expand Down Expand Up @@ -199,6 +201,35 @@ def strtobool(term, table={'false': False, 'no': False, '0': False,
return term


def jsonify(obj):
"Transforms object making it suitable for json serialization"
if isinstance(obj, (int, float, basestring, types.NoneType)):
return obj
elif isinstance(obj, (tuple, list)):
return map(jsonify, obj)
elif isinstance(obj, dict):
return dict([(k,jsonify(v)) for k,v in obj.iteritems()])
# See "Date Time String Format" in the ECMA-262 specification.
elif isinstance(obj, datetime.datetime):
r = obj.isoformat()
if obj.microsecond:
r = r[:23] + r[26:]
if r.endswith('+00:00'):
r = r[:-6] + 'Z'
return r
elif isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, datetime.time):
r = obj.isoformat()
if obj.microsecond:
r = r[:12]
return r
elif isinstance(obj, datetime.timedelta):
return str(obj)
else:
raise ValueError("Unsupported type: %s" % type(obj))


def gen_task_name(app, name, module_name):
try:
module = sys.modules[module_name]
Expand Down
6 changes: 6 additions & 0 deletions celery/worker/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from celery.utils import timeutils
from celery.utils.compat import UserDict
from celery.utils.log import get_logger
from celery.utils import jsonify

from . import state
from .state import revoked
Expand Down Expand Up @@ -287,3 +288,8 @@ def active_queues(panel):
"""Returns the queues associated with each worker."""
return [dict(queue.as_dict(recurse=True))
for queue in panel.consumer.task_consumer.queues]


@Panel.register
def dump_conf(panel, **kwargs):
return jsonify(dict(panel.app.conf))

0 comments on commit 8f3ddf0

Please sign in to comment.