Skip to content

Commit

Permalink
Remove progress, make continuous logs visible
Browse files Browse the repository at this point in the history
  • Loading branch information
rehoumir committed Aug 13, 2024
1 parent 7272485 commit b4209aa
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 132 deletions.
22 changes: 9 additions & 13 deletions project_rossum_deploy/commands/migrate/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import copy
from typing import Callable
from rich.progress import Progress
from rossum_api import ElisAPIClient
from rossum_api.api_client import Resource

Expand All @@ -11,7 +10,6 @@
MAPPING_SELECTED_ATTRIBUTE,
)
from project_rossum_deploy.utils.functions import (
PauseProgress,
extract_id_from_url,
)
from project_rossum_deploy.utils.functions import find_object_by_id
Expand Down Expand Up @@ -52,7 +50,6 @@ def replace_dependency_url(
dependency: str,
source_id_target_pairs: dict[int, list],
target_object: dict = None,
progress: Progress = None,
):
if isinstance(object[dependency], list):
replace_list_of_dependency_urls(
Expand All @@ -62,7 +59,6 @@ def replace_dependency_url(
dependency=dependency,
source_id_target_pairs=source_id_target_pairs,
target_object=target_object,
progress=progress,
)
else:
source_dependency_url = object[dependency]
Expand All @@ -87,10 +83,9 @@ def replace_dependency_url(
if settings.IS_PROJECT_IN_SAME_ORG and dependency == "organization":
return

with PauseProgress(progress):
display_warning(
f'Dependency "{dependency}" for object "{object.get('id', 'no-ID')}" was not modified. Source and target objects share the dependency. This can happen if you did not {settings.MIGRATE_COMMAND_NAME} the dependency and no target equivalent exists.'
)
display_warning(
f'Dependency "{dependency}" for object "{object.get('id', 'no-ID')}" was not modified. Source and target objects share the dependency. This can happen if you did not {settings.MIGRATE_COMMAND_NAME} the dependency and no target equivalent exists.'
)


# TODO: refactor to use the same replace URL function
Expand All @@ -101,7 +96,6 @@ def replace_list_of_dependency_urls(
dependency: str,
source_id_target_pairs: dict[int, list],
target_object: dict = None,
progress: Progress = None,
):
new_urls = []
for source_index, source_dependency_url in enumerate(object[dependency]):
Expand All @@ -121,10 +115,9 @@ def replace_list_of_dependency_urls(
new_urls.append(new_url)

if source_id_str == target_id_str:
with PauseProgress(progress):
display_warning(
f'Dependency "{dependency}"[{source_index}] for object "{object.get('id', 'no-ID')}" was not modified. Source and target objects share the dependency. This can happen if you did not {settings.MIGRATE_COMMAND_NAME} the dependency and no target equivalent exists.'
)
display_warning(
f'Dependency "{dependency}"[{source_index}] for object "{object.get('id', 'no-ID')}" was not modified. Source and target objects share the dependency. This can happen if you did not {settings.MIGRATE_COMMAND_NAME} the dependency and no target equivalent exists.'
)

# Target queues can have 'dangling' hooks that exist only on target, these should not be overwritten.
if target_object:
Expand Down Expand Up @@ -207,6 +200,9 @@ async def migrate_object_to_multiple_targets(
return list(filter(lambda x: x, results))


# TODO: add separate function for ignoring that will log and return


# Extra args are there to accomodate all upload function signatures
async def simulate_migrate_object(
client: ElisAPIClient,
Expand Down
15 changes: 3 additions & 12 deletions project_rossum_deploy/commands/migrate/hooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import functools
from rich.progress import Progress
from anyio import Path
from rossum_api import ElisAPIClient
from rossum_api.api_client import Resource
Expand All @@ -23,7 +22,6 @@
)
from project_rossum_deploy.commands.migrate.upload_helpers import upload_hook
from project_rossum_deploy.utils.functions import (
PauseProgress,
detemplatize_name_id,
extract_id_from_url,
)
Expand All @@ -35,30 +33,26 @@ async def migrate_hooks(
mapping: dict,
source_id_target_pairs: dict[int, list],
sources_by_source_id_map: dict,
progress: Progress,
plan_only: bool = False,
selected_only: bool = False,
target_objects: list[dict] = [],
errors: dict = {},
force: bool = False,
):
hook_paths = [hook_path async for hook_path in (source_path / "hooks").iterdir()]
task = progress.add_task("Releasing hooks.", total=len(hook_paths))

target_token_owner_id = ""
if not settings.IS_PROJECT_IN_SAME_ORG:
target_org_token_owner = await get_token_owner(client)
if not target_org_token_owner:
with PauseProgress(progress):
target_token_owner_id = Prompt.ask(
"Please input user ID of the hook token owner (e.g., 938382)"
)
target_token_owner_id = Prompt.ask(
"Please input user ID of the hook token owner (e.g., 938382)"
)
else:
target_token_owner_id = target_org_token_owner.id

async def migrate_hook(hook_path: Path):
if hook_path.suffix != ".json":
progress.update(task, advance=1)
return

try:
Expand Down Expand Up @@ -96,7 +90,6 @@ async def migrate_hook(hook_path: Path):
client=client,
hook=hook,
hook_mapping=hook_mapping,
progress=progress,
target_objects=target_objects,
errors=errors,
force=force,
Expand All @@ -113,8 +106,6 @@ async def migrate_hook(hook_path: Path):
plan_only=plan_only,
)
source_id_target_pairs[id].extend(results)

progress.update(task, advance=1)
except PrdVersionException as e:
raise e
except Exception as e:
Expand Down
104 changes: 49 additions & 55 deletions project_rossum_deploy/commands/migrate/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from anyio import Path
from rich import print
from rich.panel import Panel
from rich.progress import Progress
import click
from rossum_api import ElisAPIClient
from project_rossum_deploy.commands.download.download import (
Expand Down Expand Up @@ -167,61 +166,56 @@ async def migrate_project(
target_paths = await find_all_object_paths(org_path / settings.TARGET_DIRNAME)
target_objects = [await read_json(path) for path in target_paths]

with Progress() as progress:
await migrate_organization(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
target_organization_id=target_organization_id,
progress=progress,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)
await migrate_organization(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
target_organization_id=target_organization_id,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)

await migrate_schemas(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
progress=progress,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)
await migrate_hooks(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
progress=progress,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)
await migrate_workspaces(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
progress=progress,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)
await migrate_schemas(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)
await migrate_hooks(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)
await migrate_workspaces(
source_path=source_path,
client=client,
mapping=mapping,
source_id_target_pairs=source_id_target_pairs,
sources_by_source_id_map=sources_by_source_id_map,
plan_only=plan_only,
selected_only=selected_only,
target_objects=target_objects,
errors=errors_by_target_id,
force=force,
)

if not plan_only:
# Update the mapping with right hand sides (targets) created during migration
Expand Down
10 changes: 4 additions & 6 deletions project_rossum_deploy/commands/migrate/organization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from rich.progress import Progress
from anyio import Path
from rossum_api import ElisAPIClient
from rich import print
Expand Down Expand Up @@ -29,15 +28,12 @@ async def migrate_organization(
source_id_target_pairs: dict[int, list],
sources_by_source_id_map: dict,
target_organization_id: int,
progress: Progress,
plan_only: bool = False,
selected_only: bool = False,
target_objects: list[dict] = [],
errors: dict = {},
force: bool = False,
):
task = progress.add_task("Releasing organization.", total=1)

try:
organization = await read_json(source_path / "organization.json")
sources_by_source_id_map[organization["id"]] = organization
Expand All @@ -58,7 +54,6 @@ async def migrate_organization(
]

if selected_only and not check_if_selected(mapping["organization"]):
progress.update(task, advance=1)
return

if plan_only:
Expand All @@ -77,7 +72,10 @@ async def migrate_organization(
force=force,
)
]
progress.update(task, advance=1)

print(
f'Released organization "{organization['id']}" -> "{target_organization_id}".'
)
except PrdVersionException as e:
raise e
except MissingTargetOrganizationException as e:
Expand Down
5 changes: 0 additions & 5 deletions project_rossum_deploy/commands/migrate/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from anyio import Path

from rossum_api import ElisAPIClient
from rich.progress import Progress
from rich.panel import Panel
from rich import print
from rossum_api.api_client import Resource
Expand Down Expand Up @@ -34,7 +33,6 @@ async def migrate_schemas(
mapping: dict,
source_id_target_pairs: dict[int, list],
sources_by_source_id_map: dict,
progress: Progress,
plan_only: bool = False,
selected_only: bool = False,
target_objects: list[dict] = [],
Expand All @@ -44,11 +42,9 @@ async def migrate_schemas(
schema_paths = [
schema_path async for schema_path in (source_path / "schemas").iterdir()
]
task = progress.add_task("Releasing schemas.", total=len(schema_paths))

async def migrate_schema(schema_path: Path):
if schema_path.suffix != ".json":
progress.update(task, advance=1)
return

try:
Expand Down Expand Up @@ -98,7 +94,6 @@ async def migrate_schema(schema_path: Path):
)
source_id_target_pairs[id].extend(results)

progress.update(task, advance=1)
except PrdVersionException as e:
raise e
except Exception as e:
Expand Down
Loading

0 comments on commit b4209aa

Please sign in to comment.