Пример #1
0
    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)
Пример #2
0
 def start(self):
     """
     Starts all of the object's collector threads
     """
     if not self.running:
         context.log.debug('starting object %s' % self.id)
         for collector in self.collectors:
             self.threads.append(spawn(collector.run))
         self.running = True
Пример #3
0
    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