Display workers graph.
(ctx)
| 33 | @graph.command(cls=CeleryCommand, context_settings={'allow_extra_args': True}) |
| 34 | @click.pass_context |
| 35 | def workers(ctx): |
| 36 | """Display workers graph.""" |
| 37 | def simplearg(arg): |
| 38 | return maybe_list(itemgetter(0, 2)(arg.partition(':'))) |
| 39 | |
| 40 | def maybe_list(l, sep=','): |
| 41 | return l[0], l[1].split(sep) if sep in l[1] else l[1] |
| 42 | |
| 43 | args = dict(simplearg(arg) for arg in ctx.args) |
| 44 | generic = 'generic' in args |
| 45 | |
| 46 | def generic_label(node): |
| 47 | return '{} ({}://)'.format(type(node).__name__, |
| 48 | node._label.split('://')[0]) |
| 49 | |
| 50 | class Node: |
| 51 | force_label = None |
| 52 | scheme = {} |
| 53 | |
| 54 | def __init__(self, label, pos=None): |
| 55 | self._label = label |
| 56 | self.pos = pos |
| 57 | |
| 58 | def label(self): |
| 59 | return self._label |
| 60 | |
| 61 | def __str__(self): |
| 62 | return self.label() |
| 63 | |
| 64 | class Thread(Node): |
| 65 | scheme = { |
| 66 | 'fillcolor': 'lightcyan4', |
| 67 | 'fontcolor': 'yellow', |
| 68 | 'shape': 'oval', |
| 69 | 'fontsize': 10, |
| 70 | 'width': 0.3, |
| 71 | 'color': 'black', |
| 72 | } |
| 73 | |
| 74 | def __init__(self, label, **kwargs): |
| 75 | self.real_label = label |
| 76 | super().__init__( |
| 77 | label=f'thr-{next(tids)}', |
| 78 | pos=0, |
| 79 | ) |
| 80 | |
| 81 | class Formatter(GraphFormatter): |
| 82 | |
| 83 | def label(self, obj): |
| 84 | return obj and obj.label() |
| 85 | |
| 86 | def node(self, obj): |
| 87 | scheme = dict(obj.scheme) if obj.pos else obj.scheme |
| 88 | if isinstance(obj, Thread): |
| 89 | scheme['label'] = obj.real_label |
| 90 | return self.draw_node( |
| 91 | obj, dict(self.node_scheme, **scheme), |
| 92 | ) |
nothing calls this directly
no test coverage detected