Skip to content

Commit

Permalink
feat: if server is standalone send all site domain jobs to app server
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh6790 committed Aug 29, 2024
1 parent ca1522d commit cdfc0a9
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions press/press/doctype/site/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,15 +1182,23 @@ def _remove_redirects_for_all_site_domains(self):
if domains:
self.unset_redirects_in_proxy(domains)

def _get_server(self):
server = frappe.db.get_value("Server", self.server, ["proxy_server", "is_standalone"])

if server.is_standalone:
return frappe._dict({"server_type": "Server", "name": self.server})

return frappe._dict({"server_type": "Proxy Server", "name": server.proxy_server})

def set_redirects_in_proxy(self, domains: List[str]):
target = self.host_name
proxy_server = frappe.db.get_value("Server", self.server, "proxy_server")
agent = Agent(proxy_server, server_type="Proxy Server")
server = self._get_server()
agent = Agent(server.name, server_type=server.server_type)
return agent.setup_redirects(self.name, domains, target)

def unset_redirects_in_proxy(self, domains: List[str]):
proxy_server = frappe.db.get_value("Server", self.server, "proxy_server")
agent = Agent(proxy_server, server_type="Proxy Server")
server = self._get_server()
agent = Agent(server.name, server_type=server.server_type)
agent.remove_redirects(self.name, domains)

@dashboard_whitelist()
Expand All @@ -1216,11 +1224,9 @@ def archive(self, site_name=None, reason=None, force=False, skip_reload=False):
self.save()
agent.archive_site(self, site_name, force)

server = frappe.get_all(
"Server", filters={"name": self.server}, fields=["proxy_server"], limit=1
)[0]
server = self._get_server()

agent = Agent(server.proxy_server, server_type="Proxy Server")
agent = Agent(server.name, server_type=server.server_type)
agent.remove_upstream_file(
server=self.server,
site=self.name,
Expand Down Expand Up @@ -1974,8 +1980,8 @@ def reset_site_usage(self):
agent.reset_site_usage(self)

def update_site_status_on_proxy(self, status, skip_reload=False):
proxy_server = frappe.db.get_value("Server", self.server, "proxy_server")
agent = Agent(proxy_server, server_type="Proxy Server")
server = self._get_server()
agent = Agent(server.name, server_type=server.server_type)
agent.update_site_status(self.server, self.name, status, skip_reload)

def get_user_details(self):
Expand Down

0 comments on commit cdfc0a9

Please sign in to comment.