def run(self):
        current_thread().name = 'supervisor'

        # get initial config from cloud
        self.talk_with_cloud()

        # run containers
        self.containers = self.init_containers()
        if not self.containers:
            context.log.error('no containers configured, stopping')
            return

        # run bridge thread
        self.bridge = spawn(Bridge().run)

        # main cycle
        while self.is_running:
            context.inc_action_id()

            for container in self.containers.itervalues():
                container._discover_objects()
                container.run_objects()
                container.schedule_cloud_commands()

            try:
                self.talk_with_cloud(top_object=context.top_object.definition)
            except AmplifyCriticalException:
                pass

            self.check_bridge()
            time.sleep(5.0)
Esempio n. 2
0
    def run(self):
        # TODO: stop after 3 fatal errors
        current_thread().name = 'bridge'
        context.setup_thread_id()

        try:
            while True:
                m_size_b, m_rss_b = memusage.report()
                self.wait()

                context.inc_action_id()
                self.flush_meta()

                if not self.first_run:
                    self.flush_metrics()
                    self.flush_events()
                    self.flush_configs()
                else:
                    self.first_run = False

                gc.collect()

                m_size_a, m_rss_a = memusage.report()
                context.log.debug('mem before: (%s %s), after (%s, %s)' % (m_size_b, m_rss_b, m_size_a, m_rss_a))
                if m_rss_a >= m_rss_b:
                    context.log.debug('RSS MEMORY same or increased, diff %s' % (m_rss_a-m_rss_b))
                elif m_size_a >= m_size_b:
                    context.log.debug('VSIZE MEMORY same or increased, diff %s' % (m_size_a-m_size_b))
        except:
            context.default_log.error('failed', exc_info=True)
            raise
Esempio n. 3
0
    def run(self):
        current_thread().name = 'bridge'
        context.setup_thread_id()

        try:
            while True:
                self.wait()
                context.inc_action_id()
                self.flush_all()
                gc.collect()
        except:
            context.default_log.error('failed', exc_info=True)
            raise
    def run(self):
        # get correct pid
        context.set_pid()

        # set thread name
        current_thread().name = 'supervisor'

        # get initial config from cloud
        self.talk_to_cloud()

        # run containers
        self.init_containers()
        if not self.containers:
            context.log.error('no containers configured, stopping')
            return

        # run bridge thread
        self.bridge = spawn(Bridge().run)

        # main cycle
        while True:
            time.sleep(5.0)

            if not self.is_running:
                break

            try:
                context.inc_action_id()

                for container in self.containers.itervalues():
                    container._discover_objects()
                    container.run_objects()
                    container.schedule_cloud_commands()

                try:
                    self.talk_to_cloud(top_object=context.top_object.definition)
                except AmplifyCriticalException:
                    pass

                self.check_bridge()
            except OSError as e:
                if e.errno == 12:  # OSError errno 12 is a memory error (unable to allocate, out of memory, etc.)
                    context.log.error('OSError: [Errno %s] %s' % (e.errno, e.message), exc_info=True)
                    continue
                else:
                    raise e
Esempio n. 5
0
    def run(self):
        """
        Common collector cycle

        1. Collect data
        2. Sleep
        3. Stop if object stopped
        """
        current_thread().name = self.short_name
        context.setup_thread_id()

        try:
            while True:
                context.inc_action_id()
                if self.object.running:
                    self._collect()
                    self._sleep()
                else:
                    break
        except:
            context.log.error('%s failed' % self.object.id, exc_info=True)
            raise