Пример #1
0
    def _get_next_node(self, parent):
        """ Looks for next node to process """
        sorted_keys = sorted(parent.children.keys())
        for key in sorted_keys:
            node = parent.children[key]
            if node.time_record is None:
                node.request_timetable_record()
                return node
            elif self._skip_the_node(node):
                continue
            elif node.time_record.get_state() == TimeTableEntry.STATE_FINAL_RUN \
                 or node.time_record.get_state() == TimeTableEntry.STATE_IN_PROGRESS \
                 or node.time_record.get_state() == TimeTableEntry.STATE_EMBRYO:
                return node

        # special case, when all children of the parent node are not suitable for processing
        new_parent = self._get_next_parent_node(parent)
        if new_parent is not None:
            # in case all nodes are processed or blocked - look for next valid parent node
            return self._get_next_node(new_parent)
        else:
            # in all valid parents are exploited - return current node
            process_name = parent.children[sorted_keys[0]].process_name
            timestamp_now = time_helper.datetime_to_synergy(process_name, datetime.utcnow())
            return self.get_node_by_process(process_name, timestamp_now)
Пример #2
0
    def _build_tree(self, rebuild, process_name, method_get_node):
        """method builds tree by iterating from the synergy_start_timestamp to current time
        and inserting corresponding nodes"""

        if rebuild or self.build_timestamp is None:
            timestamp = settings['synergy_start_timestamp']
            timestamp = cast_to_time_qualifier(process_name, timestamp)
        else:
            timestamp = self.build_timestamp

        now = time_helper.datetime_to_synergy(process_name, datetime.utcnow())
        while now >= timestamp:
            method_get_node(timestamp)
            timestamp = time_helper.increment_time(process_name, timestamp)

        self.build_timestamp = now
Пример #3
0
    def test_datetime_to_synergy(self):
        dt = datetime(year=2010, month=12, day=31, hour=23, minute=50, second=15)

        qualifiers = [QUALIFIER_REAL_TIME,
                      QUALIFIER_HOURLY,
                      QUALIFIER_DAILY,
                      QUALIFIER_MONTHLY,
                      QUALIFIER_YEARLY]

        expected = ['20101231235015',
                    '2010123123',
                    '2010123100',
                    '2010120000',
                    '2010000000']

        for i in range(4):
            assert time_helper.datetime_to_synergy(qualifiers[i], dt) == expected[i]
Пример #4
0
    def test_datetime_to_synergy(self):
        dt = datetime(year = 2010, month = 12, day = 31, hour = 23, minute = 50, second = 15)

        processes = [process_context.PROCESS_SESSION_WORKER_00,
                     process_context.PROCESS_SITE_HOURLY,
                     process_context.PROCESS_SITE_DAILY,
                     process_context.PROCESS_SITE_MONTHLY,
                     process_context.PROCESS_SITE_YEARLY]
        
        expected = ['20101231235015',
                    '2010123123',
                    '2010123100',
                    '2010120000',
                    '2010000000']
        
        for i in range(4):
            assert time_helper.datetime_to_synergy(processes[i], dt) == expected[i]
Пример #5
0
 def actual_timeperiod(time_qualifier):
     return time_helper.datetime_to_synergy(time_qualifier, new_time)