Conditions | 7 |
Total Lines | 57 |
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 | """ |
||
23 | @staticmethod |
||
24 | def handle(_event, message, controller): |
||
25 | """ |
||
26 | Handles a JobFinishedMessage received event. |
||
27 | |||
28 | :param * _event: Not used. |
||
29 | :param enarksh.controller.message.RequestNodeActionMessage.RequestNodeActionMessage message: The message. |
||
30 | :param enarksh.controller.Controller.Controller controller: The controller. |
||
31 | """ |
||
32 | del _event |
||
33 | |||
34 | # Compose a response message for the web interface. |
||
35 | response = {'ret': 0, |
||
36 | 'new_run': 0, |
||
37 | 'message': 'OK'} |
||
38 | |||
39 | try: |
||
40 | schedule = controller.get_schedule_by_sch_id(message.sch_id) |
||
41 | if schedule: |
||
42 | actions = schedule.request_possible_node_actions(message.rnd_id) |
||
43 | else: |
||
44 | actions = Schedule.get_response_template() |
||
45 | |||
46 | if message.act_id not in actions['actions'] or not actions['actions'][message.act_id]['act_enabled']: |
||
47 | response['ret'] = -1 |
||
48 | response['message'] = 'Not a valid action' |
||
49 | else: |
||
50 | schedule = controller.get_schedule_by_sch_id(message.sch_id) |
||
51 | reload = schedule.request_node_action(message.rnd_id, |
||
52 | message.act_id, |
||
53 | message.usr_login, |
||
54 | message.mail_on_completion, |
||
55 | message.mail_on_error) |
||
56 | if reload: |
||
57 | # Schedule must be reloaded. |
||
58 | schedule = controller.reload_schedule(schedule.sch_id) |
||
59 | # A reload is only required when the schedule is been triggered. However, this trigger is lost by |
||
60 | # reloading the schedule. So, resend the trigger. |
||
61 | schedule.request_node_action(schedule.get_activate_node().rnd_id, |
||
62 | message.act_id, |
||
63 | message.usr_login, |
||
64 | message.mail_on_completion, |
||
65 | message.mail_on_error) |
||
66 | |||
67 | if message.act_id == enarksh.ENK_ACT_ID_TRIGGER: |
||
68 | response['new_run'] = 1 |
||
69 | except Exception as exception: # XXX move to MessageHandler |
||
70 | print(exception, file=sys.stderr) |
||
71 | traceback.print_exc(file=sys.stderr) |
||
72 | |||
73 | response['ret'] = -1 |
||
74 | response['message'] = 'Internal error' |
||
75 | |||
76 | DataLayer.rollback() |
||
77 | |||
78 | # Send the message to the web interface. |
||
79 | controller.message_controller.send_message('lockstep', response, True) |
||
80 | |||
82 |