本文整理汇总了Python中celery.datastructures.LRUCache.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python LRUCache.iteritems方法的具体用法?Python LRUCache.iteritems怎么用?Python LRUCache.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.datastructures.LRUCache
的用法示例。
在下文中一共展示了LRUCache.iteritems方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: State
# 需要导入模块: from celery.datastructures import LRUCache [as 别名]
# 或者: from celery.datastructures.LRUCache import iteritems [as 别名]
#.........这里部分代码省略.........
worker = self.workers[hostname] = Worker(
hostname=hostname, **kwargs)
return worker
def get_or_create_task(self, uuid):
"""Get or create task by uuid."""
try:
return self.tasks[uuid]
except KeyError:
task = self.tasks[uuid] = Task(uuid=uuid)
return task
def worker_event(self, type, fields):
"""Process worker event."""
hostname = fields.pop('hostname', None)
if hostname:
worker = self.get_or_create_worker(hostname)
handler = getattr(worker, 'on_%s' % type, None)
if handler:
handler(**fields)
def task_event(self, type, fields):
"""Process task event."""
uuid = fields.pop('uuid')
hostname = fields.pop('hostname')
worker = self.get_or_create_worker(hostname)
task = self.get_or_create_task(uuid)
handler = getattr(task, 'on_%s' % type, None)
if type == 'received':
self.task_count += 1
if handler:
handler(**fields)
else:
task.on_unknown_event(type, **fields)
task.worker = worker
def event(self, event):
with self._mutex:
return self._dispatch_event(event)
def _dispatch_event(self, event):
self.event_count += 1
event = kwdict(event)
group, _, type = event.pop('type').partition('-')
self.group_handlers[group](type, event)
if self.event_callback:
self.event_callback(self, event)
def itertasks(self, limit=None):
for index, row in enumerate(self.tasks.iteritems()):
yield row
if limit and index + 1 >= limit:
break
def tasks_by_timestamp(self, limit=None):
"""Get tasks by timestamp.
Returns a list of `(uuid, task)` tuples.
"""
return self._sort_tasks_by_time(self.itertasks(limit))
def _sort_tasks_by_time(self, tasks):
"""Sort task items by time."""
return sorted(tasks, key=lambda t: t[1].timestamp,
reverse=True)
def tasks_by_type(self, name, limit=None):
"""Get all tasks by type.
Returns a list of `(uuid, task)` tuples.
"""
sorted_tasks = self._sort_tasks_by_time((uuid, task)
for uuid, task in self.tasks.iteritems()
if task.name == name)
return sorted_tasks[0:limit or None]
def tasks_by_worker(self, hostname, limit=None):
"""Get all tasks by worker.
Returns a list of `(uuid, task)` tuples.
"""
return self._sort_tasks_by_time((uuid, task)
for uuid, task in self.itertasks(limit)
if task.worker.hostname == hostname)
def task_types(self):
"""Returns a list of all seen task types."""
return list(sorted(set(task.name for task in self.tasks.itervalues())))
def alive_workers(self):
"""Returns a list of (seemingly) alive workers."""
return [w for w in self.workers.values() if w.alive]
def __repr__(self):
return '<ClusterState: events=%s tasks=%s>' % (self.event_count,
self.task_count)