Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: DBTP-1678 maintenance page refactor #725

Merged
merged 12 commits into from
Jan 21, 2025
Merged
9 changes: 7 additions & 2 deletions dbt_platform_helper/commands/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dbt_platform_helper.domain.terraform_environment import TerraformEnvironment
from dbt_platform_helper.platform_exception import PlatformException
from dbt_platform_helper.providers.config import ConfigProvider
from dbt_platform_helper.utils.application import load_application
from dbt_platform_helper.utils.click import ClickDocOptGroup
from dbt_platform_helper.utils.versioning import (
check_platform_helper_version_needs_update,
Expand Down Expand Up @@ -36,8 +37,10 @@ def environment():
@click.option("--vpc", type=str)
def offline(app, env, svc, template, vpc):
"""Take load-balanced web services offline with a maintenance page."""

try:
MaintenancePage().activate(app, env, svc, template, vpc)
application = load_application(app)
MaintenancePage(application).activate(env, svc, template, vpc)
except PlatformException as err:
click.secho(str(err), fg="red")
raise click.Abort
Expand All @@ -48,8 +51,10 @@ def offline(app, env, svc, template, vpc):
@click.option("--env", type=str, required=True)
def online(app, env):
"""Remove a maintenance page from an environment."""

try:
MaintenancePage().deactivate(app, env)
application = load_application(app)
MaintenancePage(application).deactivate(env)
except PlatformException as err:
click.secho(str(err), fg="red")
raise click.Abort
Expand Down
11 changes: 5 additions & 6 deletions dbt_platform_helper/domain/database_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def __init__(
db_connection_string: Callable[
[Session, str, str, str, Callable], str
] = get_connection_string,
maintenance_page_provider: Callable[
[str, str, list[str], str, str], None
] = MaintenancePage(),
maintenance_page: Callable[[str, str, list[str], str, str], None] = MaintenancePage,
input: Callable[[str], str] = click.prompt,
echo: Callable[[str], str] = click.secho,
abort: Callable[[str], None] = abort_with_error,
Expand All @@ -46,7 +44,6 @@ def __init__(
self.auto_approve = auto_approve
self.vpc_provider = vpc_provider
self.db_connection_string = db_connection_string
self.maintenance_page_provider = maintenance_page_provider
self.input = input
self.echo = echo
self.abort = abort
Expand All @@ -64,6 +61,8 @@ def __init__(
except ApplicationNotFoundException:
abort(f"No such application '{app}'.")

self.maintenance_page = maintenance_page(self.application)

def _execute_operation(self, is_dump: bool, env: str, vpc_name: str, filename: str):
vpc_name = self.enrich_vpc_name(env, vpc_name)

Expand Down Expand Up @@ -183,11 +182,11 @@ def copy(
):
to_vpc = self.enrich_vpc_name(to_env, to_vpc)
if not no_maintenance_page:
self.maintenance_page_provider.activate(self.app, to_env, services, template, to_vpc)
self.maintenance_page.activate(to_env, services, template, to_vpc)
self.dump(from_env, from_vpc, f"data_dump_{to_env}")
self.load(to_env, to_vpc, f"data_dump_{to_env}")
if not no_maintenance_page:
self.maintenance_page_provider.deactivate(self.app, to_env)
self.maintenance_page.deactivate(to_env)

def is_confirmed_ready_to_load(self, env: str) -> bool:
if self.auto_approve:
Expand Down
Loading
Loading