Skip to content

Commit

Permalink
fix(Site): Simpler conditions for Activate btn to show on Pending site
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurali27 committed Oct 6, 2023
1 parent 2499c9e commit 41295a1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dashboard/src/views/site/Site.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</div>
<Button
@click="onActivateClick"
v-if="site.last_job_undelivered_for_long"
v-if="site.pending_for_long"
:variant="'solid'"
class="mr-1"
>
Expand Down
5 changes: 2 additions & 3 deletions press/api/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,7 @@ def get(name):
)[0],
"auto_updates_enabled": not site.skip_auto_updates,
},
"last_job_undelivered_for_long": site.last_job_undelivered_for_long
if site.status == "Pending"
else False,
"pending_for_long": site.pending_for_long,
}


Expand Down Expand Up @@ -1007,6 +1005,7 @@ def get_server_region_info(site) -> Dict:
@protected("Site")
def available_apps(name):
site = frappe.get_doc("Site", name)

installed_apps = [app.app for app in site.apps]

bench = frappe.get_doc("Bench", site.bench)
Expand Down
2 changes: 1 addition & 1 deletion press/api/tests/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_get_fn_returns_site_details(self):
{"team": self.team.name, "doctype_name": "Site"},
["name", "tag"],
),
"last_job_undelivered_for_long": False,
"pending_for_long": False,
},
site_details,
)
Expand Down
20 changes: 6 additions & 14 deletions press/press/doctype/site/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,20 +1315,12 @@ def disable_read_write(self):
self.enable_database_access("read_only")

@property
def last_job_undelivered_for_long(self) -> bool:
last_jobs = frappe.get_all(
"Agent Job",
["modified", "status"],
filters={"site": self.name},
order_by="creation desc",
limit=2, # for pair jobs like Archive Site
)
for job in last_jobs:
if (
job.status == "Undelivered"
and (frappe.utils.now_datetime() - job.modified).total_seconds() > 60 * 60 * 4
):
return True
def pending_for_long(self) -> bool:
if not self.status == "Pending":
return False
return (
frappe.utils.now_datetime() - self.modified
).total_seconds() > 60 * 60 * 4 # 4 hours


def site_cleanup_after_archive(site):
Expand Down

0 comments on commit 41295a1

Please sign in to comment.