Enable automatic retry by a handy way
See original GitHub issueWhat’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
andWebClient
; 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 [ ]
)
- slack_sdk.web.WebClient (Web API client)
- 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:6 (2 by maintainers)
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.
@seratch Thanks for replying, I found retries are also there in node sdk, Sorry I comment in wrong repo. https://github.com/slackapi/node-slack-sdk/blob/e7ef5289d0154370c65656fba4bbb6ee6f53d7d1/packages/web-api/README.md#automatic-retries