Skip to content

Commit

Permalink
Fix fast loop when no plugins are enabled (#3834)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss authored Oct 3, 2023
1 parent 2b6c8ea commit 8a056e5
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/dispatch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 8a056e5

Please sign in to comment.