Exemplo n.º 1
0
    def reload_tasks(self):
        """
        Called when the worker gets a 'reload' control message.
        """
        modules = sorted(self.loaded_modules.keys())
        self.logger.info("%s: Re-loading modules: %s" % (self.worker_name,', '.join(modules)))
        
        # First, find all existing Task subclasses and mark the as obsolete,
        # so that the newly-loaded version (which will have the same name) can take precedence
        old_task_classes = Task.find_all_task_classes()
        for task_class in old_task_classes:
            task_class.__obsolete__ = True

        # Toss any previously-instantiated tasks, so newly-loaded version of class can be used.
        self.known_tasks = {}

        # Now request to reload each of the originally-loaded modules:
        for module_name in modules:
            self.logger.info("%s: Re-loading module: %s" % (self.worker_name,module_name))
            mod = self.loaded_modules[module_name]
            try:
                new_mod = reload(mod)
                self.loaded_modules[module_name] = new_mod
            except:
                ex = sys.exc_info()
                self.logger.error("%s: Failed to reload module: %s: %s\n%s" % 
                                  (self.worker_name,module_name,
                                   str(ex[1]),traceback.format_exc(ex[2])))

        # Report on the new 
        self.report_known_tasks()
Exemplo n.º 2
0
    def report_known_tasks(self):
        """
        Report all the known Task classes:
        """
        modules = sorted(self.loaded_modules.keys())
        formatted = "\n    ".join([str(m) for m in modules])
        self.logger.info("%s: All loaded modules:\n    %s" % (self.worker_name,formatted))

        task_classes = Task.find_all_task_classes()
        formatted = "\n    ".join([t.__name__ for t in task_classes])
        self.logger.info("%s: All known task classes:\n    %s" % (self.worker_name,formatted))