From 1f10aeb46f81e18348b539550a7e5ef8f4945ce2 Mon Sep 17 00:00:00 2001 From: Tal Borenstein Date: Mon, 2 Dec 2024 14:56:39 +0200 Subject: [PATCH] fix: fix --- keep/api/api.py | 13 ------------- keep/api/config.py | 15 +++++++++++++++ .../versions/2024-12-01-16-40_3ad5308e7200.py | 5 ++++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/keep/api/api.py b/keep/api/api.py index e0f9cf0fd..69a5141a6 100644 --- a/keep/api/api.py +++ b/keep/api/api.py @@ -52,7 +52,6 @@ ) from keep.api.routes.auth import groups as auth_groups from keep.api.routes.auth import permissions, roles, users -from keep.api.routes.dashboard import provision_dashboards from keep.event_subscriber.event_subscriber import EventSubscriber from keep.identitymanager.identitymanagerfactory import ( IdentityManagerFactory, @@ -61,9 +60,7 @@ # load all providers into cache from keep.providers.providers_factory import ProvidersFactory -from keep.providers.providers_service import ProvidersService from keep.workflowmanager.workflowmanager import WorkflowManager -from keep.workflowmanager.workflowstore import WorkflowStore load_dotenv(find_dotenv()) keep.api.logging.setup_logging() @@ -75,7 +72,6 @@ CONSUMER = os.environ.get("CONSUMER", "true") == "true" AUTH_TYPE = os.environ.get("AUTH_TYPE", IdentityManagerTypes.NOAUTH.value).lower() -PROVISION_RESOURCES = os.environ.get("PROVISION_RESOURCES", "true") == "true" try: KEEP_VERSION = metadata.version("keep") except Exception: @@ -185,15 +181,6 @@ async def root(): async def on_startup(): logger.info("Loading providers into cache") ProvidersFactory.get_all_providers() - if PROVISION_RESOURCES: - # provision providers from env. relevant only on single tenant. - logger.info("Provisioning providers and workflows") - ProvidersService.provision_providers_from_env(SINGLE_TENANT_UUID) - logger.info("Providers loaded successfully") - WorkflowStore.provision_workflows_from_directory(SINGLE_TENANT_UUID) - logger.info("Workflows provisioned successfully") - provision_dashboards(SINGLE_TENANT_UUID) - logger.info("Dashboards provisioned successfully") # Start the services logger.info("Starting the services") # Start the scheduler diff --git a/keep/api/config.py b/keep/api/config.py index a27c4b66d..dfea1b0b1 100644 --- a/keep/api/config.py +++ b/keep/api/config.py @@ -5,10 +5,14 @@ from keep.api.api import AUTH_TYPE from keep.api.core.db_on_start import migrate_db, try_create_single_tenant from keep.api.core.dependencies import SINGLE_TENANT_UUID +from keep.api.routes.dashboard import provision_dashboards from keep.identitymanager.identitymanagerfactory import IdentityManagerTypes from keep.providers.providers_factory import ProvidersFactory +from keep.providers.providers_service import ProvidersService +from keep.workflowmanager.workflowstore import WorkflowStore PORT = int(os.environ.get("PORT", 8080)) +PROVISION_RESOURCES = os.environ.get("PROVISION_RESOURCES", "true") == "true" keep.api.logging.setup_logging() logger = logging.getLogger(__name__) @@ -19,6 +23,17 @@ def on_starting(server=None): logger.info("Keep server starting") migrate_db() + + if PROVISION_RESOURCES: + # provision providers from env. relevant only on single tenant. + logger.info("Provisioning providers and workflows") + ProvidersService.provision_providers_from_env(SINGLE_TENANT_UUID) + logger.info("Providers loaded successfully") + WorkflowStore.provision_workflows_from_directory(SINGLE_TENANT_UUID) + logger.info("Workflows provisioned successfully") + provision_dashboards(SINGLE_TENANT_UUID) + logger.info("Dashboards provisioned successfully") + # Load this early and use preloading # https://www.joelsleppy.com/blog/gunicorn-application-preloading/ # @tb: 👏 @Matvey-Kuk diff --git a/keep/api/models/db/migrations/versions/2024-12-01-16-40_3ad5308e7200.py b/keep/api/models/db/migrations/versions/2024-12-01-16-40_3ad5308e7200.py index e6c2140e3..f47399b6e 100644 --- a/keep/api/models/db/migrations/versions/2024-12-01-16-40_3ad5308e7200.py +++ b/keep/api/models/db/migrations/versions/2024-12-01-16-40_3ad5308e7200.py @@ -58,7 +58,10 @@ def downgrade() -> None: existing_nullable=True, ) batch_op.alter_column( - "settings", existing_type=sa.JSON(), type_=sa.VARCHAR(length=255), nullable=False + "settings", + existing_type=sa.JSON(), + type_=sa.VARCHAR(length=255), + nullable=False, ) # ### end Alembic commands ###