Esempio n. 1
0
class MultiWSGIApplication(object):

    def __init__(self):
        self.servers = OrderedDict()
        self.sites = Sites()
        self._lock = threading.Lock()

    def add_project(self, settings_path, logging_path=None):
        server = Server(settings_path)
        self.servers[server.name] = server
        self.sites.add(server.domains, name=server.name)
        log.debug('registered %r', server)

    def build_all(self):
        for server in itervalues(self.servers):
            server.build()

    def not_found(self):
        response = Response(charset=py2bytes("utf8"), status=404)
        response.text = not_found_response

    def reload_required(server_name):
        return False

    def reload(self, server_name):
        """
        Reload the server

        This actually creates a new server object, so that if the load fails it will continue to
        process requests with the old server instance.
        """

        log.debug("reloading '%s'", server_name)

        server = self.servers[server_name]
        try:
            new_server = Server(server.settings_path)
            new_server.build()
        except:
            log.exception("reload of '%s' failed", server_name)
        else:
            self.servers[server_name] = new_server
            self.sites.clear()
            for server in itervalues(self.servers):
                self.sites.add(server.domains, name=server.name)

    def __call__(self, environ, start_response):
        domain = environ['SERVER_NAME']
        with self._lock:
            site_match = self.sites.match(domain)
            if site_match is None:
                return self.not_found()
            server_name = site_match.data['name']
            if self.reload_required(server_name):
                self.reload(server_name)
            server = self.servers[server_name]
        return server.application(environ, start_response)
Esempio n. 2
0
class MultiWSGIApplication(object):
    def __init__(self):
        self.servers = OrderedDict()
        self.sites = Sites()
        self._lock = threading.Lock()

    def add_project(self, settings_path, logging_path=None):
        server = Server(settings_path)
        self.servers[server.name] = server
        self.sites.add(server.domains, name=server.name)
        log.debug('registered %r', server)

    def build_all(self):
        for server in itervalues(self.servers):
            server.build()

    def not_found(self):
        response = Response(charset=py2bytes("utf8"), status=404)
        response.text = not_found_response

    def reload_required(server_name):
        return False

    def reload(self, server_name):
        """
        Reload the server

        This actually creates a new server object, so that if the load fails it will continue to
        process requests with the old server instance.
        """

        log.debug("reloading '%s'", server_name)

        server = self.servers[server_name]
        try:
            new_server = Server(server.settings_path)
            new_server.build()
        except:
            log.exception("reload of '%s' failed", server_name)
        else:
            self.servers[server_name] = new_server
            self.sites.clear()
            for server in itervalues(self.servers):
                self.sites.add(server.domains, name=server.name)

    def __call__(self, environ, start_response):
        domain = environ['SERVER_NAME']
        with self._lock:
            site_match = self.sites.match(domain)
            if site_match is None:
                return self.not_found()
            server_name = site_match.data['name']
            if self.reload_required(server_name):
                self.reload(server_name)
            server = self.servers[server_name]
        return server.application(environ, start_response)
Esempio n. 3
0
 def __init__(self):
     self.servers = OrderedDict()
     self.sites = Sites()
     self._lock = threading.Lock()
     self.debug_memory = False
Esempio n. 4
0
 def __init__(self):
     self.servers = OrderedDict()
     self.sites = Sites()
     self._lock = threading.Lock()