From b3afb28ff127c7d05fa68b9bdc6152130c80d6dd Mon Sep 17 00:00:00 2001 From: Tom Tankilevitch <59158507+Tankilevitch@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:33:28 +0200 Subject: [PATCH] Fix `initlialize-port-resources` flag and change default to `True` and catch failures in ONCE resync (#202) --- CHANGELOG.md | 9 +++++++++ port_ocean/cli/commands/sail.py | 6 +++--- port_ocean/config/settings.py | 2 +- port_ocean/core/event_listener/once.py | 6 +++++- port_ocean/run.py | 1 + pyproject.toml | 2 +- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6811792e43..631d02aeea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm +## 0.4.1 (2023-11-03) + +### Bug Fixes + +- Fixed the `initialize-port-resources` option in `ocean sail` to not be a flag. +- Changed default of `initialize-port-resources` to `true`. +- Catch all exceptions in the resync of ONCE event listener,to make sure the application will exit gracefully + + ## 0.4.0 (2023-10-31) ### Features diff --git a/port_ocean/cli/commands/sail.py b/port_ocean/cli/commands/sail.py index e8579a08f4..237c20687a 100644 --- a/port_ocean/cli/commands/sail.py +++ b/port_ocean/cli/commands/sail.py @@ -33,9 +33,9 @@ "--initialize-port-resources", "initialize_port_resources", type=bool, - is_flag=True, - help="""Set to true to create default resources on installation. - If not specified, the default value is false.""", + help="""Set to False to not create default resources on installation. + If not specified, will use the environment variable `OCEAN__INITIALIZE_PORT_RESOURCES` to determine whether + to initialize resources, and if not set, will default to True.""", ) @click.option( "-O", diff --git a/port_ocean/config/settings.py b/port_ocean/config/settings.py index 45395d16ca..c12134223c 100644 --- a/port_ocean/config/settings.py +++ b/port_ocean/config/settings.py @@ -35,7 +35,7 @@ class IntegrationSettings(BaseModel, extra=Extra.allow): class IntegrationConfiguration(BaseOceanSettings, extra=Extra.allow): - initialize_port_resources: bool = False + initialize_port_resources: bool = True scheduled_resync_interval: int | None = None port: PortSettings event_listener: EventListenerSettingsType diff --git a/port_ocean/core/event_listener/once.py b/port_ocean/core/event_listener/once.py index 80f4217705..9d437c7585 100644 --- a/port_ocean/core/event_listener/once.py +++ b/port_ocean/core/event_listener/once.py @@ -52,7 +52,11 @@ async def start(self) -> None: @repeat_every(seconds=0, max_repetitions=1) async def resync_and_exit() -> None: logger.info("Once event listener started") - await self.events["on_resync"]({}) + try: + await self.events["on_resync"]({}) + except Exception: + # we catch all exceptions here to make sure the application will exit gracefully + logger.exception("Error occurred while resyncing") logger.info("Once event listener finished") logger.info("Exiting application") signal.raise_signal(signal.SIGINT) diff --git a/port_ocean/run.py b/port_ocean/run.py index 39b0bc8edc..24084a1348 100644 --- a/port_ocean/run.py +++ b/port_ocean/run.py @@ -44,6 +44,7 @@ def run( # Override config with arguments if initialize_port_resources is not None: app.config.initialize_port_resources = initialize_port_resources + if app.config.initialize_port_resources: initialize_defaults( app.integration.AppConfigHandlerClass.CONFIG_CLASS, app.config diff --git a/pyproject.toml b/pyproject.toml index 7a2e2ee14b..a7aaf4f877 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "port-ocean" -version = "0.4.0" +version = "0.4.1" description = "Port Ocean is a CLI tool for managing your Port projects." readme = "README.md" homepage = "https://app.getport.io"