Skip to content

Commit

Permalink
Update the documents
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Aug 13, 2021
1 parent 7e68718 commit 63fcdd7
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 61 deletions.
11 changes: 4 additions & 7 deletions docs-src/audit-logs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,14 @@ To use other retry handlers, you can pass a list of ``RetryHandler`` to the clie
import os
from slack_sdk.audit_logs import AuditLogsClient
from slack_sdk.http_retry import default_retry_handlers
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
client = AuditLogsClient(token=os.environ["SLACK_ORG_ADMIN_USER_TOKEN"])
# This handler does retries when HTTP status 429 is returned
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
rate_limit_handler = RateLimitErrorRetryHandler(max_retry_count=1)
client = AuditLogsClient(
token=os.environ["SLACK_ORG_ADMIN_USER_TOKEN"],
# Enable rate limited error retries as well
retry_handlers=default_retry_handlers + [rate_limit_handler],
)
# Enable rate limited error retries as well
client.retry_handlers.append(rate_limit_handler)
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.

Expand Down
11 changes: 4 additions & 7 deletions docs-src/scim/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,14 @@ To use other retry handlers, you can pass a list of ``RetryHandler`` to the clie
import os
from slack_sdk.scim import SCIMClient
from slack_sdk.http_retry import default_retry_handlers
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
client = SCIMClient(token=os.environ["SLACK_ORG_ADMIN_USER_TOKEN"])
# This handler does retries when HTTP status 429 is returned
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
rate_limit_handler = RateLimitErrorRetryHandler(max_retry_count=1)
client = SCIMClient(
token=os.environ["SLACK_ORG_ADMIN_USER_TOKEN"],
# Enable rate limited error retries as well
retry_handlers=default_retry_handlers + [rate_limit_handler],
)
# Enable rate limited error retries as well
client.retry_handlers.append(rate_limit_handler)
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.

Expand Down
11 changes: 4 additions & 7 deletions docs-src/web/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,14 @@ To use other retry handlers, you can pass a list of ``RetryHandler`` to the clie
import os
from slack_sdk.web import WebClient
from slack_sdk.http_retry import default_retry_handlers
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
client = WebClient(token=os.environ["SLACK_BOT_TOKEN"])
# This handler does retries when HTTP status 429 is returned
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
rate_limit_handler = RateLimitErrorRetryHandler(max_retry_count=1)
client = WebClient(
token=os.environ["SLACK_BOT_TOKEN"],
# Enable rate limited error retries as well
retry_handlers=default_retry_handlers + [rate_limit_handler],
)
# Enable rate limited error retries as well
client.retry_handlers.append(rate_limit_handler)
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.

Expand Down
16 changes: 7 additions & 9 deletions docs-src/webhook/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,16 @@ To use other retry handlers, you can pass a list of ``RetryHandler`` to the clie

.. code-block:: python
from slack_sdk.http_retry import default_retry_handlers
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
from slack_sdk.webhook import WebhookClient
url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
webhook = WebhookClient(url=url)
# This handler does retries when HTTP status 429 is returned
from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
rate_limit_handler = RateLimitErrorRetryHandler(max_retry_count=1)
from slack_sdk.webhook import WebhookClient
url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
webhook = WebhookClient(
url=url,
# Enable rate limited error retries as well
retry_handlers=default_retry_handlers + [rate_limit_handler],
)
# Enable rate limited error retries as well
client.retry_handlers.append(rate_limit_handler)
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.

Expand Down
11 changes: 4 additions & 7 deletions docs/audit-logs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,14 @@ <h2>RetryHandler<a class="headerlink" href="#retryhandler" title="Permalink to t
<p>To use other retry handlers, you can pass a list of <code class="docutils literal notranslate"><span class="pre">RetryHandler</span></code> to the client constructor. For instance, you can add the built-in <code class="docutils literal notranslate"><span class="pre">RateLimitErrorRetryHandler</span></code> this way:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">slack_sdk.audit_logs</span> <span class="kn">import</span> <span class="n">AuditLogsClient</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry</span> <span class="kn">import</span> <span class="n">default_retry_handlers</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">AuditLogsClient</span><span class="p">(</span><span class="n">token</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;SLACK_ORG_ADMIN_USER_TOKEN&quot;</span><span class="p">])</span>

<span class="c1"># This handler does retries when HTTP status 429 is returned</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<span class="n">rate_limit_handler</span> <span class="o">=</span> <span class="n">RateLimitErrorRetryHandler</span><span class="p">(</span><span class="n">max_retry_count</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

<span class="n">client</span> <span class="o">=</span> <span class="n">AuditLogsClient</span><span class="p">(</span>
<span class="n">token</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;SLACK_ORG_ADMIN_USER_TOKEN&quot;</span><span class="p">],</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">retry_handlers</span><span class="o">=</span><span class="n">default_retry_handlers</span> <span class="o">+</span> <span class="p">[</span><span class="n">rate_limit_handler</span><span class="p">],</span>
<span class="p">)</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">client</span><span class="o">.</span><span class="n">retry_handlers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rate_limit_handler</span><span class="p">)</span>
</pre></div>
</div>
<p>Creating your own ones is also quite simple. Defining a new class that inherits <code class="docutils literal notranslate"><span class="pre">slack_sdk.http_retry.RetryHandler</span></code> (<code class="docutils literal notranslate"><span class="pre">AsyncRetryHandler</span></code> for asyncio apps) and implements required methods (internals of <code class="docutils literal notranslate"><span class="pre">can_retry</span></code> / <code class="docutils literal notranslate"><span class="pre">prepare_for_next_retry</span></code>). Check the built-in ones’ source code for learning how to properly implement.</p>
Expand Down
11 changes: 4 additions & 7 deletions docs/scim/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,14 @@ <h2>RetryHandler<a class="headerlink" href="#retryhandler" title="Permalink to t
<p>To use other retry handlers, you can pass a list of <code class="docutils literal notranslate"><span class="pre">RetryHandler</span></code> to the client constructor. For instance, you can add the built-in <code class="docutils literal notranslate"><span class="pre">RateLimitErrorRetryHandler</span></code> this way:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">slack_sdk.scim</span> <span class="kn">import</span> <span class="n">SCIMClient</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry</span> <span class="kn">import</span> <span class="n">default_retry_handlers</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">SCIMClient</span><span class="p">(</span><span class="n">token</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;SLACK_ORG_ADMIN_USER_TOKEN&quot;</span><span class="p">])</span>

<span class="c1"># This handler does retries when HTTP status 429 is returned</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<span class="n">rate_limit_handler</span> <span class="o">=</span> <span class="n">RateLimitErrorRetryHandler</span><span class="p">(</span><span class="n">max_retry_count</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

<span class="n">client</span> <span class="o">=</span> <span class="n">SCIMClient</span><span class="p">(</span>
<span class="n">token</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;SLACK_ORG_ADMIN_USER_TOKEN&quot;</span><span class="p">],</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">retry_handlers</span><span class="o">=</span><span class="n">default_retry_handlers</span> <span class="o">+</span> <span class="p">[</span><span class="n">rate_limit_handler</span><span class="p">],</span>
<span class="p">)</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">client</span><span class="o">.</span><span class="n">retry_handlers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rate_limit_handler</span><span class="p">)</span>
</pre></div>
</div>
<p>Creating your own ones is also quite simple. Defining a new class that inherits <code class="docutils literal notranslate"><span class="pre">slack_sdk.http_retry.RetryHandler</span></code> (<code class="docutils literal notranslate"><span class="pre">AsyncRetryHandler</span></code> for asyncio apps) and implements required methods (internals of <code class="docutils literal notranslate"><span class="pre">can_retry</span></code> / <code class="docutils literal notranslate"><span class="pre">prepare_for_next_retry</span></code>). Check the built-in ones’ source code for learning how to properly implement.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions docs/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -748,17 +748,14 @@ <h2>RetryHandler<a class="headerlink" href="#retryhandler" title="Permalink to t
<p>To use other retry handlers, you can pass a list of <code class="docutils literal notranslate"><span class="pre">RetryHandler</span></code> to the client constructor. For instance, you can add the built-in <code class="docutils literal notranslate"><span class="pre">RateLimitErrorRetryHandler</span></code> this way:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">slack_sdk.web</span> <span class="kn">import</span> <span class="n">WebClient</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry</span> <span class="kn">import</span> <span class="n">default_retry_handlers</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">WebClient</span><span class="p">(</span><span class="n">token</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;SLACK_BOT_TOKEN&quot;</span><span class="p">])</span>

<span class="c1"># This handler does retries when HTTP status 429 is returned</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<span class="n">rate_limit_handler</span> <span class="o">=</span> <span class="n">RateLimitErrorRetryHandler</span><span class="p">(</span><span class="n">max_retry_count</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

<span class="n">client</span> <span class="o">=</span> <span class="n">WebClient</span><span class="p">(</span>
<span class="n">token</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;SLACK_BOT_TOKEN&quot;</span><span class="p">],</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">retry_handlers</span><span class="o">=</span><span class="n">default_retry_handlers</span> <span class="o">+</span> <span class="p">[</span><span class="n">rate_limit_handler</span><span class="p">],</span>
<span class="p">)</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">client</span><span class="o">.</span><span class="n">retry_handlers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rate_limit_handler</span><span class="p">)</span>
</pre></div>
</div>
<p>Creating your own ones is also quite simple. Defining a new class that inherits <code class="docutils literal notranslate"><span class="pre">slack_sdk.http_retry.RetryHandler</span></code> (<code class="docutils literal notranslate"><span class="pre">AsyncRetryHandler</span></code> for asyncio apps) and implements required methods (internals of <code class="docutils literal notranslate"><span class="pre">can_retry</span></code> / <code class="docutils literal notranslate"><span class="pre">prepare_for_next_retry</span></code>). Check the built-in ones’ source code for learning how to properly implement.</p>
Expand Down
16 changes: 7 additions & 9 deletions docs/webhook/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,16 @@ <h2>AsyncWebhookClient<a class="headerlink" href="#asyncwebhookclient" title="Pe
<h2>RetryHandler<a class="headerlink" href="#retryhandler" title="Permalink to this headline"></a></h2>
<p>With the default settings, only <code class="docutils literal notranslate"><span class="pre">ConnectionErrorRetryHandler</span></code> with its default configuration (=only one retry in the manner of <a class="reference external" href="https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/">exponential backoff and jitter</a> is enabled. The retry handler retries if an API client encounters a connectivity-related failure (e.g., Connection reset by peer).</p>
<p>To use other retry handlers, you can pass a list of <code class="docutils literal notranslate"><span class="pre">RetryHandler</span></code> to the client constructor. For instance, you can add the built-in <code class="docutils literal notranslate"><span class="pre">RateLimitErrorRetryHandler</span></code> this way:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slack_sdk.http_retry</span> <span class="kn">import</span> <span class="n">default_retry_handlers</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slack_sdk.webhook</span> <span class="kn">import</span> <span class="n">WebhookClient</span>
<span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
<span class="n">webhook</span> <span class="o">=</span> <span class="n">WebhookClient</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">)</span>

<span class="c1"># This handler does retries when HTTP status 429 is returned</span>
<span class="kn">from</span> <span class="nn">slack_sdk.http_retry.builtin_handlers</span> <span class="kn">import</span> <span class="n">RateLimitErrorRetryHandler</span>
<span class="n">rate_limit_handler</span> <span class="o">=</span> <span class="n">RateLimitErrorRetryHandler</span><span class="p">(</span><span class="n">max_retry_count</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">slack_sdk.webhook</span> <span class="kn">import</span> <span class="n">WebhookClient</span>
<span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
<span class="n">webhook</span> <span class="o">=</span> <span class="n">WebhookClient</span><span class="p">(</span>
<span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">retry_handlers</span><span class="o">=</span><span class="n">default_retry_handlers</span> <span class="o">+</span> <span class="p">[</span><span class="n">rate_limit_handler</span><span class="p">],</span>
<span class="p">)</span>
<span class="c1"># Enable rate limited error retries as well</span>
<span class="n">client</span><span class="o">.</span><span class="n">retry_handlers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rate_limit_handler</span><span class="p">)</span>
</pre></div>
</div>
<p>Creating your own ones is also quite simple. Defining a new class that inherits <code class="docutils literal notranslate"><span class="pre">slack_sdk.http_retry.RetryHandler</span></code> (<code class="docutils literal notranslate"><span class="pre">AsyncRetryHandler</span></code> for asyncio apps) and implements required methods (internals of <code class="docutils literal notranslate"><span class="pre">can_retry</span></code> / <code class="docutils literal notranslate"><span class="pre">prepare_for_next_retry</span></code>). Check the built-in ones’ source code for learning how to properly implement.</p>
Expand Down

0 comments on commit 63fcdd7

Please sign in to comment.