GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( d4663b...83e50d )
by P.R.
02:57
created

RequestNodeActionMessageEventHandler.handle()   C

Complexity

Conditions 7

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
c 1
b 0
f 0
dl 0
loc 57
rs 6.6397

How to fix   Long Method   

Long Method

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:

1
"""
2
Enarksh
3
4
Copyright 2013-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
9
import sys
10
import traceback
11
12
import enarksh
13
from enarksh.DataLayer import DataLayer
14
from enarksh.controller.Schedule import Schedule
15
16
17
class RequestNodeActionMessageEventHandler:
18
    """
19
    An event handler for a RequestNodeActionMessage received events.
20
    """
21
22
    # ------------------------------------------------------------------------------------------------------------------
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
81
# ----------------------------------------------------------------------------------------------------------------------
82