From 8a056e5351da09b2320fcfbebd554dd55d14b759 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Tue, 3 Oct 2023 08:30:16 -0700 Subject: [PATCH] Fix fast loop when no plugins are enabled (#3834) --- src/dispatch/cli.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/dispatch/cli.py b/src/dispatch/cli.py index 1b11c602b563..bac15191de17 100644 --- a/src/dispatch/cli.py +++ b/src/dispatch/cli.py @@ -775,6 +775,7 @@ def signals_group(): @signals_group.command("consume") def consume_signals(): """Runs a continuous process that consumes signals from the specified plugin.""" + import time import concurrent.futures from dispatch.common.utils.cli import install_plugins @@ -795,20 +796,23 @@ def consume_signals(): session = sessionmaker(bind=schema_engine)() projects = project_service.get_all(db_session=session) - for project in projects: - plugins = plugin_service.get_active_instances( - db_session=session, plugin_type="signal-consumer", project_id=project.id - ) - - if not plugins: - log.warning( - f"No signals consumed. No signal-consumer plugins enabled. Project: {project.name}. Organization: {project.organization.name}" + with concurrent.futures.ProcessPoolExecutor() as executor: + for project in projects: + plugins = plugin_service.get_active_instances( + db_session=session, plugin_type="signal-consumer", project_id=project.id ) - for plugin in plugins: - log.debug(f"Consuming signals for plugin {plugin.plugin.slug}") - with concurrent.futures.ProcessPoolExecutor() as executor: - executor.submit(plugin.instance.consume, session, project) + if not plugins: + log.warning( + f"No signals consumed. No signal-consumer plugins enabled. Project: {project.name}. Organization: {project.organization.name}" + ) + + for plugin in plugins: + log.debug(f"Consuming signals for plugin: {plugin.plugin.slug}") + executor.submit(plugin.instance.consume, session, project) + + # if no plugins are configured, we sleep for 10 minutes + time.sleep(600) @signals_group.command("process")