Skip to content

Commit

Permalink
fix: Run backend correlation in optimized way (#1658)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk authored Aug 20, 2024
1 parent 95addff commit ddba734
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ def update_action(
return found_action


def get_tenants_configurations() -> List[Tenant]:
def get_tenants_configurations(only_with_config=False) -> List[Tenant]:
with Session(engine) as session:
try:
tenants = session.exec(select(Tenant)).all()
Expand All @@ -1918,6 +1918,8 @@ def get_tenants_configurations() -> List[Tenant]:

tenants_configurations = {}
for tenant in tenants:
if only_with_config and not tenant.configuration:
continue
tenants_configurations[tenant.id] = tenant.configuration or {}

return tenants_configurations
Expand Down
3 changes: 2 additions & 1 deletion keep/api/tasks/process_background_ai_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ async def process_background_ai_task(
tenant_configuration = TenantConfiguration()

if mine_incidents_and_create_objects is not NotImplemented:
for tenant in get_tenants_configurations():
tenants = get_tenants_configurations(only_with_config=True)
for tenant in tenants:
if is_ee_enabled_for_tenant(tenant, tenant_configuration=tenant_configuration):
# Because of https://github.com/python-arq/arq/issues/432 we need to check if the job is already running
# The other option would be to twick "keep_result" but it will make debugging harder
Expand Down

0 comments on commit ddba734

Please sign in to comment.