Skip to content

Commit

Permalink
feat(site): Add api to activate/deactivate site for update
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Jan 21, 2025
1 parent 19cb2ea commit 054890d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
27 changes: 21 additions & 6 deletions agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ def update_site_migrate_job(

with suppress(Exception):
site.bench_execute(
"execute"
" frappe.website.doctype.website_theme.website_theme"
".generate_theme_files_if_not_exist"
"execute frappe.website.doctype.website_theme.website_theme.generate_theme_files_if_not_exist"
)

if activate:
Expand All @@ -274,6 +272,25 @@ def update_site_migrate_job(
# v12 does not have build_search_index command
site.build_search_index()

@job("Deactivate Site", priority="high")
def deactivate_site_job(self, name, bench):
source = Bench(bench, self)
site = Site(name, source)

site.enable_maintenance_mode()
site.wait_till_ready()

@job("Activate Site", priority="high")
def activate_site_job(self, name, bench):
source = Bench(bench, self)
site = Site(name, source)

site.disable_maintenance_mode()
with suppress(Exception):
# Don't fail job on failure
# v12 does not have build_search_index command
site.build_search_index()

@job("Recover Failed Site Migrate", priority="high")
def update_site_recover_migrate_job(self, name, source, target, activate, rollback_scripts):
source = Bench(source, self)
Expand Down Expand Up @@ -336,9 +353,7 @@ def move_site_to_bench(self, name, source, target, deactivate, activate, skip_fa

with suppress(Exception):
site.bench_execute(
"execute"
" frappe.website.doctype.website_theme.website_theme"
".generate_theme_files_if_not_exist"
"execute frappe.website.doctype.website_theme.website_theme.generate_theme_files_if_not_exist"
)

if activate:
Expand Down
19 changes: 19 additions & 0 deletions agent/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,25 @@ def clear_site_cache(bench, site):
return {"job": job}


@application.route(
"/benches/<string:bench>/sites/<string:site>/activate",
methods=["POST"],
)
@validate_bench_and_site
def activate_site(bench, site):
job = Server().activate_site_job(site, bench)
return {"job": job}


@application.route(
"/benches/<string:bench>/sites/<string:site>/deactivate",
methods=["POST"],
)
def deactivate_site(bench, site):
job = Server().deactivate_site_job(site, bench)
return {"job": job}


@application.route(
"/benches/<string:bench>/sites/<string:site>/update/migrate",
methods=["POST"],
Expand Down

0 comments on commit 054890d

Please sign in to comment.