本文整理汇总了Python中celery.task.control.inspect方法的典型用法代码示例。如果您正苦于以下问题:Python control.inspect方法的具体用法?Python control.inspect怎么用?Python control.inspect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.task.control
的用法示例。
在下文中一共展示了control.inspect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: celery_info
# 需要导入模块: from celery.task import control [as 别名]
# 或者: from celery.task.control import inspect [as 别名]
def celery_info():
from celery.task.control import inspect
i = inspect()
info = []
active = i.active()
if not active:
return [('Error', 'Could not inspect Celery: it may be down.')]
for worker, tasks in list(active.items()):
if tasks:
taskstr = '; '.join("%s(*%s, **%s)" % (t['name'], t['args'], t['kwargs'])
for t in tasks)
else:
taskstr = 'None'
info.append((worker + ' active', taskstr))
for worker, tasks in list(i.scheduled().items()):
info.append((worker + ' scheduled', len(tasks)))
info.sort()
return info
示例2: get_celery_worker_status
# 需要导入模块: from celery.task import control [as 别名]
# 或者: from celery.task.control import inspect [as 别名]
def get_celery_worker_status():
"""
Detects if working
"""
# from
# http://stackoverflow.com/questions/8506914/detect-whether-celery-is-available-running
ERROR_KEY = "ERROR"
try:
from celery.task.control import inspect
insp = inspect()
d = insp.stats()
if not d:
d = {ERROR_KEY: 'No running Celery workers were found.'}
except IOError as e:
from errno import errorcode
msg = "Error connecting to the backend: " + str(e)
if len(e.args) > 0 and errorcode.get(e.args[0]) == 'ECONNREFUSED':
msg += ' Check that the RabbitMQ server is running.'
d = {ERROR_KEY: msg}
except ImportError as e:
d = {ERROR_KEY: str(e)}
return d
示例3: get_celery_worker_status
# 需要导入模块: from celery.task import control [as 别名]
# 或者: from celery.task.control import inspect [as 别名]
def get_celery_worker_status():
ERROR_KEY = "ERROR"
try:
from celery.task.control import inspect
insp = inspect()
d = insp.stats()
if not d:
d = {ERROR_KEY: 'No running Celery workers were found.'}
except IOError as e:
from errno import errorcode
msg = "Error connecting to the backend: " + str(e)
if len(e.args) > 0 and errorcode.get(e.args[0]) == 'ECONNREFUSED':
msg += ' Check that the RabbitMQ server is running.'
d = {ERROR_KEY: msg}
except ImportError as e:
d = {ERROR_KEY: str(e)}
return d
示例4: task_stats
# 需要导入模块: from celery.task import control [as 别名]
# 或者: from celery.task.control import inspect [as 别名]
def task_stats(request):
celery_inspect = control.inspect()
stats = celery_inspect.stats()
active = celery_inspect.active()
scheduled = celery_inspect.scheduled()
context = cornerwise_admin.each_context(request)
context.update({"nodes": {node: {"tasks": nodestats["total"],
"active": active[node],
"scheduled": scheduled[node],
"up_since": uptime_to_date(int(nodestats["clock"]))}
for node, nodestats in (stats.items() if stats else [])},
"title": "Celery Stats"})
return render(request, "admin/task_stats.djhtml", context)
示例5: is_task_active
# 需要导入模块: from celery.task import control [as 别名]
# 或者: from celery.task.control import inspect [as 别名]
def is_task_active(fun, task_id, args):
from celery.task.control import inspect
if not args:
args = "()" # empty args
i = inspect()
active_tasks = i.active()
for _, tasks in active_tasks.items():
for task in tasks:
if task.get("id") == task_id:
continue
if task.get("name") == fun and task.get("args") == str(args):
return True
return False
示例6: _worker_inspector
# 需要导入模块: from celery.task import control [as 别名]
# 或者: from celery.task.control import inspect [as 别名]
def _worker_inspector(task):
global _inspector
if _inspector is None:
_inspector = inspect([task.request.hostname])
return _inspector
# Get this list of currently revoked tasks for this worker
示例7: _is_update_in_progress
# 需要导入模块: from celery.task import control [as 别名]
# 或者: from celery.task.control import inspect [as 别名]
def _is_update_in_progress(cls, device_id):
active = inspect().active()
if not active:
return False
# check if there's any other running task before adding it
for task_list in active.values():
for task in task_list:
if task['name'] == _TASK_NAME and str(device_id) in task['args']:
return True
return False