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.

NodeActionMessageBaseEventHandler.base_handle()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 15
cp 0
crap 42
rs 7.5384
1
"""
2
Enarksh
3
4
Copyright 2013-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
from enarksh.C import C
9
from enarksh.controller.Schedule import Schedule
10
11
12
class NodeActionMessageBaseEventHandler:
13
    """
14
    A base event handler for a NodeActionMessage or received events.
15
    """
16
17
    # ------------------------------------------------------------------------------------------------------------------
18
    @staticmethod
19
    def base_handle(controller, response, sch_id, rnd_id, act_id):
20
        """
21
        Handles a NodeActionMessage received event.
22
23
        :param enarksh.controller.Controller.Controller controller: The controller.
24
        :param dict response: The response to the client.
25
        :param int sch_id: The ID of the schedule.
26
        :param int rnd_id: The ID of the node.
27
        :param int act_id: The ID of the requested action.
28
        """
29
        schedule = controller.get_schedule_by_sch_id(sch_id)
30
        if schedule:
31
            actions = schedule.request_possible_node_actions(rnd_id)
32
        else:
33
            actions = Schedule.get_response_template()
34
35
        if act_id not in actions['actions'] or not actions['actions'][act_id]['act_enabled']:
36
            response['ret'] = -1
37
            response['message'] = 'Not a valid action'
38
        else:
39
            schedule = controller.get_schedule_by_sch_id(sch_id)
40
            reload = schedule.request_node_action(rnd_id, act_id)
41
            if reload:
42
                # Schedule must be reloaded.
43
                schedule = controller.reload_schedule(schedule.sch_id)
44
                # A reload is only required when the schedule is been triggered. However, this trigger is lost by
45
                # reloading the schedule. So, resend the trigger.
46
                schedule.request_node_action(schedule.get_activate_node().rnd_id, act_id)
47
48
            if act_id == C.ENK_ACT_ID_TRIGGER:
49
                response['new_run'] = 1
50
51
# ----------------------------------------------------------------------------------------------------------------------
52