本文整理汇总了Python中pyon.ion.exchange.ExchangeManager.list_bindings_for_queue方法的典型用法代码示例。如果您正苦于以下问题:Python ExchangeManager.list_bindings_for_queue方法的具体用法?Python ExchangeManager.list_bindings_for_queue怎么用?Python ExchangeManager.list_bindings_for_queue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.ion.exchange.ExchangeManager
的用法示例。
在下文中一共展示了ExchangeManager.list_bindings_for_queue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QueueBlame
# 需要导入模块: from pyon.ion.exchange import ExchangeManager [as 别名]
# 或者: from pyon.ion.exchange.ExchangeManager import list_bindings_for_queue [as 别名]
#.........这里部分代码省略.........
exchange_diff_add = post_exchanges.difference(pre_exchanges)
binds_diff_add = post_binds.difference(pre_binds)
queue_diff_sub = pre_queues.difference(post_queues)
exchange_diff_sub = pre_exchanges.difference(post_exchanges)
binds_diff_sub = pre_binds.difference(post_binds)
# maintain active queue set
map(self._active_queues.add, queue_diff_add)
map(self._active_queues.discard, queue_diff_sub)
# maintain changelog for tests
self._test_changes[tid] = (queue_diff_add, queue_diff_sub, exchange_diff_add, exchange_diff_sub, binds_diff_add, binds_diff_sub)
# add any new leftover queues to the list
for q in queue_diff_add:
if not q in self._queues_declared:
self._queues_declared.append(q)
# get stats about each leftover queue and record the access
raw_queues_list = self.ex_manager._list_queues()
raw_queues = { str(x['name']) : x for x in raw_queues_list }
for q in self._queues_declared:
# detect if queue has been deleted (and not readded)
if len(self._queues[q]) > 0 and isinstance(self._queues[q][-1], str) and not q in queue_diff_add:
continue
# did we just delete it this test? add the sentinel
if q in queue_diff_sub:
self._queues[q].append(tid)
continue
# record the test, # messages on it, + bindings on the queue, - bindings on the queue
self._queues[q].append( (tid,
str(raw_queues[q]['messages']),
[x for x in binds_diff_add if str(x[1]) == str(q)],
[x for x in binds_diff_sub if str(x[1]) == str(q)]))
# are we supposed to purge it / kill bindings?
if self._queueblame_purge and raw_queues[q]['messages'] > 0:
# remove bindings via API
binds = self.ex_manager.list_bindings_for_queue(q)
for bind in binds:
self.ex_manager.delete_binding_tuple(bind)
# add to list of removed bindings for report
rem_binds = self._queues[q][-1][3]
rem_binds.append(tuple(bind[0:2] + (bind[2] + " (PURGED)",)))
# purge
self.ex_manager.purge_queue(q)
def report(self, stream):
table = []
for q in self._queues_declared:
qd = self._queues[q]
# first rows are:
# queue + test # messages
# +B exchange binding
table.append([q, "+", qd[0][0], qd[0][1]])
for bind in qd[0][2]:
table.append(["", "", " +B ex: %s key: %s" % (bind[0], bind[2]), ""])
# add rest of accesses
# test # messages
# +B exchange binding
# -B exchange binding
for qdd in qd[1:]:
if isinstance(qdd, str):
table.append(["", "-", qdd, ""])
else:
table.append(["", "", qdd[0], qdd[1]])
for bind in qdd[2]:
table.append(["", "", " +B ex: %s key: %s" % (bind[0], bind[2]), ""])
for bind in qdd[3]:
table.append(["", "", " -B ex: %s key: %s" % (bind[0], bind[2]), ""])
# header
table.insert(0, ['Queue', '', 'Test', '# Msg'])
# get widths
widths = [max([len(row[x]) for row in table]) for x in xrange(len(table[0]))]
fmt_out = [" ".join([x.ljust(widths[i]) for i, x in enumerate(row)]) for row in table]
# insert col separation row
fmt_out.insert(1, " ".join([''.ljust(widths[i], '=') for i in xrange(len(widths))]))
# write this all to sstream
stream.write("Queue blame report (purge: %s)\n" % (self._queueblame_purge))
stream.write("\n".join(fmt_out))
stream.write("\n")