Python-slack-sdk: Enable automatic retry by a handy way

Created on 3 Dec 2020  路  3Comments  路  Source: slackapi/python-slack-sdk

What's this?

WebClient does not retry HTTP requests in any case. Developers may want to have auto-retries for intermittent and/or recoverable errors. We can consider adding a new option (or its underlying function) for auto-retry on the library side.

Basic Design Idea

The primary option should be a retry configuration like urllib3 offers: https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html

retry = Retry(connect=5, read=2, redirect=5, ratelimited=10)
client = WebClient(token="xoxb-", retry=retry)

WebClient can translate the configuration to an error handling function under the hood. The possible function interface can be as below (note: this is a completely pseudo code):

def retry_handler(client, req, error, retry_num) -> Union[SlackResponse, Exception]:
     if is_recoverable(error):
         return client.retry(req)
     else:
         return error

client = WebClient(token="xoxb-", retry_handler=retry_handler)

Most developers just need retry config but some may want to take full control of the logic (e.g., implementing exponential backoff retries etc).

Factors to Consider

  • [ ] Provide the same interface to both AsyncWebClient and WebClient; this means the compatibility with AIOHTTP must be evaluated before deciding the interface
  • [ ] Provide the option to WebClient and WebhookClient
  • [ ] Enable overwriting per endpoint; developers may want to turn retries on only for a particular endpoint
  • [ ] Smooth integration with Bolt for Python; the design should not block giving the config from App class constructor
  • [ ] Handle ratelimited errors appropriately

... what else?

Category (place an x in each of the [ ])

  • [x] slack_sdk.web.WebClient (Web API client)
  • [x] slack_sdk.webhook.WebhookClient (Incoming Webhook, response_url sender)
  • [ ] slack_sdk.models (UI component builders)
  • [ ] slack_sdk.oauth (OAuth Flow Utilities)
  • [ ] slack_sdk.rtm.RTMClient (RTM client)
  • [ ] slack_sdk.signature (Request Signature Verifier)

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

3x discussion enhancement web-client

Most helpful comment

Also a note, the retry should not only retry the command but retry the recreating the connection. Often times Slack responds with a connection reset by peer when you are trying mass calls and to recover you need to reinitialize the client.

All 3 comments

Also a note, the retry should not only retry the command but retry the recreating the connection. Often times Slack responds with a connection reset by peer when you are trying mass calls and to recover you need to reinitialize the client.

Due to my capacity for the next minor release, I've moved this feature from 3.5 to 3.6.

Would love to see this feature!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tinoargentino picture tinoargentino  路  3Comments

Terrance picture Terrance  路  3Comments

charlesreid1 picture charlesreid1  路  3Comments

kompotkot picture kompotkot  路  4Comments

ErikKalkoken picture ErikKalkoken  路  3Comments