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.

handle()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 61

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 61
ccs 0
cts 22
cp 0
crap 6
rs 9.5147

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
import logging
9
10
from enarksh.DataLayer import DataLayer
11
from enarksh.xml_reader.XmlReader import XmlReader
12
from enarksh.xml_reader.node.FakeParent import FakeParent
13
14
15
class DynamicWorkerDefinitionMessageEventHandler:
16
    """
17
    An event handler for a DynamicWorkerDefinitionMessage received events.
18
    """
19
20
    # ------------------------------------------------------------------------------------------------------------------
21
    @staticmethod
22
    def handle(_event, message, controller):
23
        """
24
        Handles a DynamicWorkerDefinitionMessage received event.
25
26
        :param * _event: Not used.
27
        :param enarksh.controller.message.DynamicWorkerDefinitionMessage.DynamicWorkerDefinitionMessage message:
28
               The message.
29
        :param enarksh.controller.Controller.Controller controller: The controller.
30
        """
31
        del _event
32
33
        log = logging.getLogger('enarksh')
34
35
        try:
36
            log.debug('DynamicWorkerDefinitionMessageEventHandler: rnd_id: {}'.format(message.rnd_id))
37
38
            # Get info of the dynamic node.
39
            info = DataLayer.enk_back_run_node_get_dynamic_info_by_generator(message.rnd_id)
40
41
            schedule = controller.get_schedule_by_sch_id(message.sch_id)
42
            parent = FakeParent(schedule,
43
                                controller.host_resources,
44
                                info['nod_id_outer_worker'],
45
                                info['rnd_id_outer_worker'])
46
47
            # Validate XML against XSD.
48
            reader = XmlReader()
49
            inner_worker = reader.parse_dynamic_worker(message.xml, parent)
50
            name = inner_worker.name
51
52
            # Note: Dynamic node is the parent of the worker node which is the parent of the inner worker node.
53
            inner_worker.set_levels(info['nod_recursion_level'] + 2)
54
55
            # Store the dynamically defined inner worker node.
56
            inner_worker.store(info['srv_id'], 0)
57
58
            # Create dependencies between the input and output port of the worker node and its child node(s).
59
            DataLayer.enk_back_node_dynamic_add_dependencies(info['nod_id_outer_worker'], inner_worker.nod_id)
60
61
            # XXX trigger reload of front end
62
63
            # Unload the schedule to force a reload of the schedule with new nodes added.
64
            # XXX This step must be replaced with adding dependencies between the new simple nodes and existing simple
65
            # nodes (successors and predecessors) and register listeners for the inner node and its new child nodes.
66
            controller.unload_schedule(message.sch_id)
67
68
            response = {'ret':     0,
69
                        'message': 'Worker {} successfully loaded'.format(name)}
70
71
            DataLayer.commit()
72
        except Exception as exception:
73
            log.exception('Error')
74
75
            response = {'ret':     -1,
76
                        'message': str(exception)}
77
78
            DataLayer.rollback()
79
80
        # Send the message to the job.
81
        controller.message_controller.send_message('lockstep', response, True)
82
83
# ----------------------------------------------------------------------------------------------------------------------
84