fix(alerts): improve Slack API rate limiting for large workspaces (#35622)

This commit is contained in:
Marcos Amorim
2025-10-24 13:02:41 -04:00
committed by GitHub
parent 93cb60b24e
commit c3b8c96db6
4 changed files with 90 additions and 17 deletions

View File

@@ -26,10 +26,23 @@ logger = logging.getLogger(__name__)
@celery_app.task(name="slack.cache_channels")
def cache_channels() -> None:
cache_timeout = current_app.config["SLACK_CACHE_TIMEOUT"]
retry_count = current_app.config.get("SLACK_API_RATE_LIMIT_RETRY_COUNT", 2)
logger.info(
"Starting Slack channels cache warm-up task "
"(cache_timeout=%ds, retry_count=%d)",
cache_timeout,
retry_count,
)
try:
get_channels(
force=True, cache_timeout=current_app.config["SLACK_CACHE_TIMEOUT"]
)
get_channels(force=True, cache_timeout=cache_timeout)
except Exception as ex:
logger.exception("An error occurred while caching Slack channels: %s", ex)
logger.exception(
"Failed to cache Slack channels: %s. "
"If this is due to rate limiting, consider increasing "
"SLACK_API_RATE_LIMIT_RETRY_COUNT.",
str(ex),
)
raise