Conditions | 2 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 | """ |
||
22 | @staticmethod |
||
23 | def handle(_event, message, controller): |
||
24 | """ |
||
25 | Handles a DynamicWorkerDefinitionMessage received event. |
||
26 | |||
27 | :param * _event: Not used. |
||
28 | :param enarksh.controller.message.DynamicWorkerDefinitionMessage.DynamicWorkerDefinitionMessage message: |
||
29 | The message. |
||
30 | :param enarksh.controller.Controller.Controller controller: The controller. |
||
31 | """ |
||
32 | del _event |
||
33 | |||
34 | try: |
||
35 | print('rnd_id: ' + str(message.rnd_id)) |
||
36 | |||
37 | # Get info of the dynamic node. |
||
38 | info = DataLayer.enk_back_run_node_get_dynamic_info_by_generator(message.rnd_id) |
||
39 | |||
40 | schedule = controller.get_schedule_by_sch_id(message.sch_id) |
||
41 | parent = FakeParent(schedule, |
||
42 | controller.host_resources, |
||
43 | info['nod_id_outer_worker'], |
||
44 | info['rnd_id_outer_worker']) |
||
45 | |||
46 | # Validate XML against XSD. |
||
47 | reader = XmlReader() |
||
48 | inner_worker = reader.parse_dynamic_worker(message.xml, parent) |
||
49 | name = inner_worker.name |
||
50 | |||
51 | # Note: Dynamic node is the parent of the worker node which is the parent of the inner worker node. |
||
52 | inner_worker.set_levels(info['nod_recursion_level'] + 2) |
||
53 | |||
54 | # Store the dynamically defined inner worker node. |
||
55 | inner_worker.store(info['srv_id'], 0) |
||
56 | |||
57 | # Create dependencies between the input and output port of the worker node and its child node(s). |
||
58 | DataLayer.enk_back_node_dynamic_add_dependencies(info['nod_id_outer_worker'], inner_worker.nod_id) |
||
59 | |||
60 | # XXX trigger reload of front end |
||
61 | |||
62 | # Unload the schedule to force a reload of the schedule with new nodes added. |
||
63 | controller.unload_schedule(message.sch_id) |
||
64 | |||
65 | response = {'ret': 0, |
||
66 | 'message': "Worker '%s' successfully loaded." % name} |
||
67 | |||
68 | except Exception as exception: |
||
69 | print(exception, file=sys.stderr) |
||
70 | response = {'ret': -1, |
||
71 | 'message': str(exception)} |
||
72 | traceback.print_exc(file=sys.stderr) |
||
73 | |||
74 | # Send the message to the job. |
||
75 | controller.message_controller.send_message('lockstep', response, True) |
||
76 | |||
78 |