Skip to content

Commit

Permalink
version 3.26.2
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Jan 9, 2024
1 parent b6b9527 commit 03bd99e
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 116 deletions.
288 changes: 174 additions & 114 deletions docs/api-docs/slack_sdk/socket_mode/aiohttp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,48 +376,68 @@ <h1 class="title">Module <code>slack_sdk.socket_mode.aiohttp</code></h1>
return self.build_session_id(self.current_session)

async def connect(self):
old_session: Optional[ClientWebSocketResponse] = None if self.current_session is None else self.current_session
if self.wss_uri is None:
# If the underlying WSS URL does not exist,
# acquiring a new active WSS URL from the server-side first
self.wss_uri = await self.issue_new_wss_url()

self.current_session = await self.aiohttp_client_session.ws_connect(
self.wss_uri,
autoping=False,
heartbeat=self.ping_interval,
proxy=self.proxy,
ssl=self.web_client.ssl,
)
session_id: str = await self.session_id()
self.auto_reconnect_enabled = self.default_auto_reconnect_enabled
self.stale = False
self.logger.info(f&#34;A new session ({session_id}) has been established&#34;)

# The first ping from the new connection
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;Sending a ping message with the newly established connection ({session_id})...&#34;)
t = time.time()
await self.current_session.ping(f&#34;sdk-ping-pong:{t}&#34;)

if self.current_session_monitor is not None:
self.current_session_monitor.cancel()
# This loop is used to ensure when a new session is created,
# a new monitor and a new message receiver are also created.
# If a new session is created but we failed to create the new
# monitor or the new message, we should try it.
while True:
try:
old_session: Optional[ClientWebSocketResponse] = (
None if self.current_session is None else self.current_session
)

self.current_session_monitor = asyncio.ensure_future(self.monitor_current_session())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new monitor_current_session() executor has been recreated for {session_id}&#34;)
# If the old session is broken (e.g. reset by peer), it might fail to close it.
# We don&#39;t want to retry when this kind of cases happen.
try:
# We should close old session before create a new one. Because when disconnect
# reason is `too_many_websockets`, we need to close the old one first to
# to decrease the number of connections.
self.auto_reconnect_enabled = False
if old_session is not None:
await old_session.close()
old_session_id = self.build_session_id(old_session)
self.logger.info(f&#34;The old session ({old_session_id}) has been abandoned&#34;)
except Exception as e:
self.logger.exception(f&#34;Failed to close the old session : {e}&#34;)

if self.wss_uri is None:
# If the underlying WSS URL does not exist,
# acquiring a new active WSS URL from the server-side first
self.wss_uri = await self.issue_new_wss_url()

self.current_session = await self.aiohttp_client_session.ws_connect(
self.wss_uri,
autoping=False,
heartbeat=self.ping_interval,
proxy=self.proxy,
ssl=self.web_client.ssl,
)
session_id: str = await self.session_id()
self.auto_reconnect_enabled = self.default_auto_reconnect_enabled
self.stale = False
self.logger.info(f&#34;A new session ({session_id}) has been established&#34;)

if self.message_receiver is not None:
self.message_receiver.cancel()
# The first ping from the new connection
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;Sending a ping message with the newly established connection ({session_id})...&#34;)
t = time.time()
await self.current_session.ping(f&#34;sdk-ping-pong:{t}&#34;)

self.message_receiver = asyncio.ensure_future(self.receive_messages())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new receive_messages() executor has been recreated for {session_id}&#34;)
if self.current_session_monitor is not None:
self.current_session_monitor.cancel()
self.current_session_monitor = asyncio.ensure_future(self.monitor_current_session())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new monitor_current_session() executor has been recreated for {session_id}&#34;)

if old_session is not None:
await old_session.close()
old_session_id = self.build_session_id(old_session)
self.logger.info(f&#34;The old session ({old_session_id}) has been abandoned&#34;)
if self.message_receiver is not None:
self.message_receiver.cancel()
self.message_receiver = asyncio.ensure_future(self.receive_messages())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new receive_messages() executor has been recreated for {session_id}&#34;)
break
except Exception as e:
self.logger.exception(f&#34;Failed to connect (error: {e}); Retrying...&#34;)
await asyncio.sleep(self.ping_interval)

async def disconnect(self):
if self.current_session is not None:
Expand Down Expand Up @@ -832,48 +852,68 @@ <h2 id="args">Args</h2>
return self.build_session_id(self.current_session)

async def connect(self):
old_session: Optional[ClientWebSocketResponse] = None if self.current_session is None else self.current_session
if self.wss_uri is None:
# If the underlying WSS URL does not exist,
# acquiring a new active WSS URL from the server-side first
self.wss_uri = await self.issue_new_wss_url()

self.current_session = await self.aiohttp_client_session.ws_connect(
self.wss_uri,
autoping=False,
heartbeat=self.ping_interval,
proxy=self.proxy,
ssl=self.web_client.ssl,
)
session_id: str = await self.session_id()
self.auto_reconnect_enabled = self.default_auto_reconnect_enabled
self.stale = False
self.logger.info(f&#34;A new session ({session_id}) has been established&#34;)

# The first ping from the new connection
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;Sending a ping message with the newly established connection ({session_id})...&#34;)
t = time.time()
await self.current_session.ping(f&#34;sdk-ping-pong:{t}&#34;)

if self.current_session_monitor is not None:
self.current_session_monitor.cancel()
# This loop is used to ensure when a new session is created,
# a new monitor and a new message receiver are also created.
# If a new session is created but we failed to create the new
# monitor or the new message, we should try it.
while True:
try:
old_session: Optional[ClientWebSocketResponse] = (
None if self.current_session is None else self.current_session
)

self.current_session_monitor = asyncio.ensure_future(self.monitor_current_session())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new monitor_current_session() executor has been recreated for {session_id}&#34;)
# If the old session is broken (e.g. reset by peer), it might fail to close it.
# We don&#39;t want to retry when this kind of cases happen.
try:
# We should close old session before create a new one. Because when disconnect
# reason is `too_many_websockets`, we need to close the old one first to
# to decrease the number of connections.
self.auto_reconnect_enabled = False
if old_session is not None:
await old_session.close()
old_session_id = self.build_session_id(old_session)
self.logger.info(f&#34;The old session ({old_session_id}) has been abandoned&#34;)
except Exception as e:
self.logger.exception(f&#34;Failed to close the old session : {e}&#34;)

if self.wss_uri is None:
# If the underlying WSS URL does not exist,
# acquiring a new active WSS URL from the server-side first
self.wss_uri = await self.issue_new_wss_url()

self.current_session = await self.aiohttp_client_session.ws_connect(
self.wss_uri,
autoping=False,
heartbeat=self.ping_interval,
proxy=self.proxy,
ssl=self.web_client.ssl,
)
session_id: str = await self.session_id()
self.auto_reconnect_enabled = self.default_auto_reconnect_enabled
self.stale = False
self.logger.info(f&#34;A new session ({session_id}) has been established&#34;)

if self.message_receiver is not None:
self.message_receiver.cancel()
# The first ping from the new connection
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;Sending a ping message with the newly established connection ({session_id})...&#34;)
t = time.time()
await self.current_session.ping(f&#34;sdk-ping-pong:{t}&#34;)

self.message_receiver = asyncio.ensure_future(self.receive_messages())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new receive_messages() executor has been recreated for {session_id}&#34;)
if self.current_session_monitor is not None:
self.current_session_monitor.cancel()
self.current_session_monitor = asyncio.ensure_future(self.monitor_current_session())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new monitor_current_session() executor has been recreated for {session_id}&#34;)

if old_session is not None:
await old_session.close()
old_session_id = self.build_session_id(old_session)
self.logger.info(f&#34;The old session ({old_session_id}) has been abandoned&#34;)
if self.message_receiver is not None:
self.message_receiver.cancel()
self.message_receiver = asyncio.ensure_future(self.receive_messages())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new receive_messages() executor has been recreated for {session_id}&#34;)
break
except Exception as e:
self.logger.exception(f&#34;Failed to connect (error: {e}); Retrying...&#34;)
await asyncio.sleep(self.ping_interval)

async def disconnect(self):
if self.current_session is not None:
Expand Down Expand Up @@ -1082,48 +1122,68 @@ <h3>Methods</h3>
<span>Expand source code</span>
</summary>
<pre><code class="python">async def connect(self):
old_session: Optional[ClientWebSocketResponse] = None if self.current_session is None else self.current_session
if self.wss_uri is None:
# If the underlying WSS URL does not exist,
# acquiring a new active WSS URL from the server-side first
self.wss_uri = await self.issue_new_wss_url()

self.current_session = await self.aiohttp_client_session.ws_connect(
self.wss_uri,
autoping=False,
heartbeat=self.ping_interval,
proxy=self.proxy,
ssl=self.web_client.ssl,
)
session_id: str = await self.session_id()
self.auto_reconnect_enabled = self.default_auto_reconnect_enabled
self.stale = False
self.logger.info(f&#34;A new session ({session_id}) has been established&#34;)

# The first ping from the new connection
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;Sending a ping message with the newly established connection ({session_id})...&#34;)
t = time.time()
await self.current_session.ping(f&#34;sdk-ping-pong:{t}&#34;)

if self.current_session_monitor is not None:
self.current_session_monitor.cancel()
# This loop is used to ensure when a new session is created,
# a new monitor and a new message receiver are also created.
# If a new session is created but we failed to create the new
# monitor or the new message, we should try it.
while True:
try:
old_session: Optional[ClientWebSocketResponse] = (
None if self.current_session is None else self.current_session
)

self.current_session_monitor = asyncio.ensure_future(self.monitor_current_session())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new monitor_current_session() executor has been recreated for {session_id}&#34;)
# If the old session is broken (e.g. reset by peer), it might fail to close it.
# We don&#39;t want to retry when this kind of cases happen.
try:
# We should close old session before create a new one. Because when disconnect
# reason is `too_many_websockets`, we need to close the old one first to
# to decrease the number of connections.
self.auto_reconnect_enabled = False
if old_session is not None:
await old_session.close()
old_session_id = self.build_session_id(old_session)
self.logger.info(f&#34;The old session ({old_session_id}) has been abandoned&#34;)
except Exception as e:
self.logger.exception(f&#34;Failed to close the old session : {e}&#34;)

if self.wss_uri is None:
# If the underlying WSS URL does not exist,
# acquiring a new active WSS URL from the server-side first
self.wss_uri = await self.issue_new_wss_url()

self.current_session = await self.aiohttp_client_session.ws_connect(
self.wss_uri,
autoping=False,
heartbeat=self.ping_interval,
proxy=self.proxy,
ssl=self.web_client.ssl,
)
session_id: str = await self.session_id()
self.auto_reconnect_enabled = self.default_auto_reconnect_enabled
self.stale = False
self.logger.info(f&#34;A new session ({session_id}) has been established&#34;)

if self.message_receiver is not None:
self.message_receiver.cancel()
# The first ping from the new connection
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;Sending a ping message with the newly established connection ({session_id})...&#34;)
t = time.time()
await self.current_session.ping(f&#34;sdk-ping-pong:{t}&#34;)

self.message_receiver = asyncio.ensure_future(self.receive_messages())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new receive_messages() executor has been recreated for {session_id}&#34;)
if self.current_session_monitor is not None:
self.current_session_monitor.cancel()
self.current_session_monitor = asyncio.ensure_future(self.monitor_current_session())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new monitor_current_session() executor has been recreated for {session_id}&#34;)

if old_session is not None:
await old_session.close()
old_session_id = self.build_session_id(old_session)
self.logger.info(f&#34;The old session ({old_session_id}) has been abandoned&#34;)</code></pre>
if self.message_receiver is not None:
self.message_receiver.cancel()
self.message_receiver = asyncio.ensure_future(self.receive_messages())
if self.logger.level &lt;= logging.DEBUG:
self.logger.debug(f&#34;A new receive_messages() executor has been recreated for {session_id}&#34;)
break
except Exception as e:
self.logger.exception(f&#34;Failed to connect (error: {e}); Retrying...&#34;)
await asyncio.sleep(self.ping_interval)</code></pre>
</details>
</dd>
<dt id="slack_sdk.socket_mode.aiohttp.SocketModeClient.disconnect"><code class="name flex">
Expand Down
2 changes: 1 addition & 1 deletion docs/api-docs/slack_sdk/version.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1 class="title">Module <code>slack_sdk.version</code></h1>
<span>Expand source code</span>
</summary>
<pre><code class="python">&#34;&#34;&#34;Check the latest version at https://pypi.org/project/slack-sdk/&#34;&#34;&#34;
__version__ = &#34;3.26.1&#34;</code></pre>
__version__ = &#34;3.26.2&#34;</code></pre>
</details>
</section>
<section>
Expand Down
2 changes: 1 addition & 1 deletion slack_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Check the latest version at https://pypi.org/project/slack-sdk/"""
__version__ = "3.26.1"
__version__ = "3.26.2"

0 comments on commit 03bd99e

Please sign in to comment.