Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't process subscriptions with no assets #17988

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ee/tasks/subscriptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import structlog
from prometheus_client import Counter
from sentry_sdk import capture_exception
from sentry_sdk import capture_exception, capture_message

from ee.tasks.subscriptions.email_subscriptions import send_email_subscription_report
from ee.tasks.subscriptions.slack_subscriptions import send_slack_subscription_report
Expand Down Expand Up @@ -41,11 +41,15 @@ def _deliver_subscription_report(
# Same value as before so nothing to do
return

insights, assets = generate_assets(subscription)

if not assets:
capture_message("No assets are in this subscription", tags={"subscription_id": subscription.id})
return

if subscription.target_type == "email":
SUBSCRIPTION_QUEUED.labels(destination="email").inc()

insights, assets = generate_assets(subscription)

# Send emails
emails = subscription.target_value.split(",")
if is_new_subscription_target:
Expand Down Expand Up @@ -77,7 +81,6 @@ def _deliver_subscription_report(
elif subscription.target_type == "slack":
SUBSCRIPTION_QUEUED.labels(destination="slack").inc()

insights, assets = generate_assets(subscription)
try:
send_slack_subscription_report(
subscription, assets, total_asset_count=len(insights), is_new_subscription=is_new_subscription_target
Expand Down
5 changes: 4 additions & 1 deletion ee/tasks/subscriptions/subscription_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def generate_assets(
]
ExportedAsset.objects.bulk_create(assets)

if not assets:
return insights, assets

# Wait for all assets to be exported
tasks = [exporter.export_asset.si(asset.id) for asset in assets]
# run them one after the other so we don't exhaust celery workers
# run them one after the other, so we don't exhaust celery workers
parallel_job = chain(*tasks).apply_async()

wait_for_parallel_celery_group(
Expand Down
Loading