Skip to content

Commit 48cf9e2

Browse files
committed
fix: Update server queries for site and bench placement
- Prefer use_for_new_sites and use_for_new_benches via ordering instead of filtering to avoid selection failures
1 parent 59613a7 commit 48cf9e2

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

press/api/site.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _new(site, server: str | None = None, ignore_plan_validation: bool = False):
180180
if server:
181181
bench_query = bench_query.where(Server.name == server)
182182
else:
183-
bench_query = bench_query.where(Server.use_for_new_sites == 1)
183+
bench_query.orderby(Server.use_for_new_sites, order=frappe.qb.desc)
184184

185185
bench = bench_query.run(as_dict=True).pop()
186186

press/press/doctype/site/site.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ def _get_benches_for_(self, proxy_servers, release_group_names=None, host_on_sha
29242924

29252925
if host_on_shared_server:
29262926
bench_query = bench_query.where(servers.public == 1)
2927-
bench_query = bench_query.where(servers.use_for_new_sites == 1)
2927+
bench_query = bench_query.orderby(servers.use_for_new_sites, order=frappe.qb.desc)
29282928

29292929
if release_group_names:
29302930
groups = frappe.qb.DocType("Release Group")

press/press/doctype/site_group_deploy/site_group_deploy.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ def check_if_rg_or_site_exists(self):
8181
frappe.throw(f"Site with subdomain {self.subdomain} already exists")
8282

8383
def get_optimal_server_for_private_bench(self):
84-
server = frappe.get_all(
85-
"Server",
86-
filters={
87-
"status": "Active",
88-
"cluster": self.cluster,
89-
"provider": self.provider,
90-
"public": 1,
91-
"use_for_new_benches": 1,
92-
},
93-
pluck="name",
94-
)
84+
Server = frappe.qb.doctype("Server")
85+
server = (
86+
frappe.qb.from_(Server)
87+
.select(Server.name)
88+
.where(
89+
(Server.status == "Active")
90+
& (Server.cluster == self.cluster)
91+
& (Server.provider == self.provider)
92+
& (Server.public == 1)
93+
)
94+
.orderby(Server.use_for_new_benches, order=frappe.qb.desc)
95+
).run(pluck=True)
9596

9697
return server[0] if server else None
9798

0 commit comments

Comments
 (0)