Conditions | 9 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 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, 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 | - count: Number of polls to complete. |
||
30 | - pause: Number of seconds to wait between each cycle. |
||
31 | |||
32 | Returns |
||
33 | True: As PollNow does not return any data. |
||
34 | |||
35 | Raises: |
||
36 | IndexError: When a nodes is not found. |
||
37 | """ |
||
38 | |||
39 | self.results = {'down': [], |
||
40 | 'up': [], |
||
41 | 'extra_count': False} |
||
42 | |||
43 | self.connect() |
||
44 | self.orion_nodes = [] |
||
45 | |||
46 | for node in nodes: |
||
47 | orion_node = self.get_node(node) |
||
48 | |||
49 | if orion_node.npm: |
||
50 | self.orion_nodes.append(orion_node.npm_id) |
||
51 | else: |
||
52 | error_msg = "Node not found" |
||
53 | send_user_error(error_msg) |
||
54 | raise ValueError(error_msg) |
||
55 | |||
56 | for c in range(count): |
||
57 | self._pollnow_nodes(count, pause) |
||
58 | |||
59 | if len(self.orion_nodes) == 0: |
||
60 | self.results['last_count'] = c |
||
61 | break |
||
62 | else: |
||
63 | self.results['last_count'] = count |
||
64 | |||
65 | if len(self.orion_nodes) > 0: |
||
66 | self.results['extra_pass'] = True |
||
67 | for c in range(count): |
||
68 | self._pollnow_nodes(count, pause) |
||
69 | else: |
||
70 | self.results['left'] = self.orion_nodes |
||
71 | |||
72 | # These Invoke's return None, so we just return True |
||
73 | return self.results |
||
74 | |||
107 |