Conditions | 9 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more |
||
23 | def run(self, nodes, platform, count, pause): |
||
24 | """ |
||
25 | Invoke a PollNow verb against a Orion Node. |
||
26 | |||
27 | Args: |
||
28 | - node: The caption in Orion of the node to poll. |
||
29 | - platform: The orion platform to act on. |
||
30 | - count: Number of polls to complete. |
||
31 | - pause: Number of seconds to wait between each cycle. |
||
32 | |||
33 | Returns |
||
34 | True: As PollNow does not return any data. |
||
35 | |||
36 | Raises: |
||
37 | IndexError: When a nodes is not found. |
||
38 | """ |
||
39 | |||
40 | self.results = {'down': [], |
||
41 | 'up': [], |
||
42 | 'extra_count': False} |
||
43 | |||
44 | self.connect(platform) |
||
45 | self.orion_nodes = [] |
||
46 | |||
47 | for node in nodes: |
||
48 | orion_node = self.get_node(node) |
||
49 | |||
50 | if orion_node.npm: |
||
51 | self.orion_nodes.append(orion_node.npm_id) |
||
52 | else: |
||
53 | error_msg = "Node not found" |
||
54 | send_user_error(error_msg) |
||
55 | raise ValueError(error_msg) |
||
56 | |||
57 | for c in range(count): |
||
58 | self._pollnow_nodes(count, pause) |
||
59 | |||
60 | if len(self.orion_nodes) == 0: |
||
61 | self.results['last_count'] = c |
||
62 | break |
||
63 | else: |
||
64 | self.results['last_count'] = count |
||
65 | |||
66 | if len(self.orion_nodes) > 0: |
||
67 | self.results['extra_pass'] = True |
||
68 | for c in range(count): |
||
69 | self._pollnow_nodes(count, pause) |
||
70 | else: |
||
71 | self.results['left'] = self.orion_nodes |
||
72 | |||
73 | # These Invoke's return None, so we just return True |
||
74 | return self.results |
||
75 | |||
108 |