Skip to content

Commit

Permalink
fix: don't process subscriptions with no assets (#17988)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored and daibhin committed Oct 23, 2023
1 parent 9d36e03 commit 83a130b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit 83a130b

Please sign in to comment.