Skip to content

Commit

Permalink
adds rate limit handler from slack SDK (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfrye committed May 3, 2024
1 parent 03c44cb commit 5923bff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions 10_integrations/webscraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ async def get_links(url: str) -> set[str]:
return set(links)


slack_sdk_image = modal.Image.debian_slim().pip_install("slack-sdk")
slack_sdk_image = modal.Image.debian_slim(python_version="3.10").pip_install(
"slack-sdk==3.27.1"
)


@app.function(
Expand All @@ -48,9 +50,13 @@ async def get_links(url: str) -> set[str]:
)
def bot_token_msg(channel, message):
import slack_sdk
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler

print(f"Posting {message} to #{channel}")
client = slack_sdk.WebClient(token=os.environ["SLACK_BOT_TOKEN"])
rate_limit_handler = RateLimitErrorRetryHandler(max_retry_count=3)
client.retry_handlers.append(rate_limit_handler)

print(f"Posting {message} to #{channel}")
client.chat_postMessage(channel=channel, text=message)


Expand Down

0 comments on commit 5923bff

Please sign in to comment.